Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner needing help!
#1
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!!!!)
Reply
#2
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Brilliant! Thank you so much. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  needing some help to write some code for a game calculator rymdaksel 1 408 Jan-02-2024, 09:56 AM
Last Post: deanhystad
  Needing to Check Every Quarter Hour bill_z 10 3,000 Feb-09-2022, 07:23 PM
Last Post: menator01
  Noob needing guidance.... bako 0 1,859 Mar-29-2020, 06:55 PM
Last Post: bako
  Global Variables - Some Points Needing Clarification. adt 4 2,961 Nov-30-2019, 01:23 PM
Last Post: adt
  Beginner needing advice with data files JFI2019 2 2,203 Nov-06-2019, 04:56 PM
Last Post: JFI2019
  Typical beginner needing some help foxter00 1 2,657 May-08-2019, 11:46 PM
Last Post: michalmonday
  New user/beginner needing help oldDog 3 3,224 Apr-17-2018, 02:31 PM
Last Post: oldDog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020