This is my first python program and forum post so bear with me if I don't this right. I have an if statement asking for instructions or to begin my game. This program will be presented to middle schoolers so I made a while loop for the name input statement that won't let them continue if they input "69", "420", or "ur mom". But for some reason, it doesn't ask the input statement asking the user for a name and gives a typeError. The exact error message is
Thanks Python community for taking the time to consider this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Traceback (most recent call last): File "C:/Users/break/PycharmProjects/Tutorial/GameExp.py" , line 16 , in <module> while name in nameTwo: TypeError: 'in <string>' requires string as left operand, not set [python] This is my code: [python] # This section gives the instructions or lets the user start the game instruction = input ( "Press [H] for instructions or any other key to start:" ) if instruction = = "H" : print ( "This game is a turn based adventure in which you have to gather information, make tactical choices, and fight enemies to win. Enter all inputs with capital letters." ) else : print ( "Beginning game..." ) # A basic 14 year old proof name input name = { "420" , "ur mom" , "69" } nameTwo = " " while name in nameTwo: name = input ( "Please enter a name:" ) if name = = "420" : print ( "Try again..." ) elif name = = "ur mom" : print ( "Try again..." ) elif name = = ( "69" ): print ( "Try again..." ) break else : print ( "Hello" + name) |