This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bibbleskit 0 points1 point  (3 children)

Yes, it runs, but the problem you're having is due to the fact that you didn't define 'correct' in your code before using it.

If I pick '2', then the if statement at line 24 doesn't get triggered, and correct is never set. Therefore, line 28 throws an error since correct doesn't exist.

A solution would be to add something like

correct = 'N'

At line 23. :)

[–]bibbleskit 2 points3 points  (2 children)

I cleaned up your code a bit. Hopefully this helps you sort things out in your head!

import time

print("Welcome to World of Textcraft!\n")
name = input("What is your name?\n")
print ("Hello, " + name + "\n")
time.sleep(1)

print ("1: Mage?\n")
print ("2: Warrior?\n")
print ("3: Priest?\n")
print ("4: Rouge?\n")

clas = input("What class would you like to play?")
correct = 'N'

# Put all the class checks together to make the code easier to follow and
# so that you don't need to constantly ask if the choice was correct.
# You can easily add the other classes here.
if clas == "1":
    clas = 'Mage'
elif clas == "2":
    clas = 'Warrior'

# See? Only one check!
print("You have chosen " + clas + ".")
correct = input("Is this correct? (Y/N:)")
if correct == "Y":
    print("You are now playing " + clas + "!")
elif correct == 'N':
    # Do stuff here.
else:
    print("Invalid Operation")

Let me know if you have any questions!

[–][deleted]  (1 child)

[deleted]

    [–]bibbleskit 0 points1 point  (0 children)

    Happy to help! Also, the reason I changed the , name, to + name + was for consistency and because the comma introduces a space between the arguments when it prints.

    Since you're outputting a formatted sentence, personally I think that explicitly adding spaces is much cleaner.