Python Forum

Full Version: Beginner needing help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to learn Python. For me the best way to learn is to try and apply the subject to an interest. In this case I am trying to make a small quiz. The code is displayed below (I hope). Essentially I want the user to input an answer. Based on the answer I want to print either Correct or Wrong. Can anyone help me with this. I assume it's really easy and I'm being stupid.

print "Welcome to the ultimate football quiz"

print "Question 1"

print "Who scored the first ever premier league goal?"

print "1: Brian Deane"
print "2: Eric Cantona"
print "3: Alan Shearer"
print "4: Dion Dubline"

answer = float(input("Please enter answer "))
if answer >1
print (CORRECT!!!!)
A couple of things. Since you are only checking the value of whole numbers, the correct way would be:
answer = int(input("Please enter answer "))
next, you need to terminate the if/elif/else clauses with a colon ":"

You are checking the value of answer to the number 1, in this case you are checking answer against 2, 3 and 4.  If the user enters any of these values you are saying that the user is correct, which isn't true (at least I don't think so, since I don't know the answer.)  The better way is to look for the "True" first:

if answer == 1:    # Or what ever the correct answer is
    print ("CORRECT!!!!")    # Make sure you use 'quotes' around text you want printed
else:
    print("LOSER!!!!")
Finally, all your 'print' functions at the beginning need to be in parenthesis.
Brilliant! Thank you so much. :)