Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to make a program that uses class function to ask users to input a string of parenthesis and I need to give an error message if they entered a non-parenthesis.

What I have tried:

def valid_char():
    while True:
        char="("")""[""]""{""}""()[]{}"
        
        try:
            int_char=char(input("Enter your string:")
            
        except ValueError:
            print("Error, please input a valid parenthesis:")
            
        elif:
            print("This is your string", int_char)
            break
        
valid_char()




This is the result:
except ValueError:
         ^
SyntaxError: invalid syntax
Posted
Updated 5-Oct-21 20:13pm

1 solution

There is a closing circular brackets missing:
int_char=char(input("Enter your string:")


Try:
int_char=char(input("Enter your string:"))
 
Share this answer
 
Comments
lil_mint 12-Jan-21 3:05am    
Oh yeah.. I forgot in that part. Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900