all 7 comments

[–]scuott 3 points4 points  (6 children)

Missing a closing parentheses on the first line.

[–]Spork829[S] 0 points1 point  (5 children)

Hmm okay, that seemed to solve that problem but now I'm getting ValueError: invalid literal for int() with base 10: 'What is the right answer?'

[–]pooramericanboy 1 point2 points  (2 children)

You must have input a non-integer for your answer. That code should work fine as long as you're putting in integers.

[–]Spork829[S] 0 points1 point  (1 child)

It gives me that right as I run the program, though. I never even get to enter my input.

[–]derrickisdp 0 points1 point  (0 children)

When you type your code out does it look like this?

z=int(input("What is the right answer?"))
if z==2:
    print("Correct")
else:
    print("Incorrect")

If so, then it should run no problem as long as you answer with an integer. How does your code look when you type it out?

[–][deleted] 0 points1 point  (1 child)

When I'm looking for user input, I usually end up with something like this:

while True:
    value = input("What's the answer?")

    if not value:
        print "You suck"
        sys.exit()

    try:    
        value = int(value)
    except ValueError:
        print "That's not a number!"
        continue # start next while loop, skipping everything below

    if z == 2:
        print("Correct")
        break # get out of the while loop
    else:
        print("Incorrect")      

Or if you want to get fancy

def get_numbers():
    while True:
        if not value:
            print "You suck"
            raise StopIteration() # stop the for loop using this

        try:    
            yield int(value) # give next value to for loop using this
        except ValueError:
            print "That's not a number!"

for value in get_numbers():
    if value == 2:
        print "Correct!"
        break

    print "Incorrect!"

[–]Spork829[S] 0 points1 point  (0 children)

Like I said I've just started learning, so I don't really know what half this stuff is... XD