Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding error?
#2
Lets make it easy, since the code is pretty repetitive, and look at the first option only.

name = input("Hello, what is your name?")
print(name, ",welcome to the car quiz!")
 
first_answer = 2
score = 0
input("Q1 - Which country does Porsche come from?")
input("1 - England")
input("2 - Germany")
input("3 - Austria")
input("4 - Portugal")
user1 = input("Enter your answer:")
 
if user1 == first_answer:
score = score + 1
else:
score = score + 0
The main problem is you are trying to compare 'strings' with 'numbers' and the result will always be false. Note that you have defined 'score' and 'first_answer' as integers, while requesting from user1 a 'string' value. Remember, on it's own, the input() function returns a string. We can modify this behavior by telling the function what we want returned.
Thus
user1 = input("Enter your answer:")
becomes
user1 = int(input("Enter your answer:"))
Now your if/else statements will be comparing numbers with numbers.

One other point, all your 'input()s' on lines 6 thru 10 and the other segments as well, need only be 'print', having them as inputs requires the user to hit enter after every line, which I'm sure is not your intent.
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


Messages In This Thread
Coding error? - by Mugwash - Apr-04-2018, 10:22 AM
RE: Coding error? - by sparkz_alot - Apr-04-2018, 02:37 PM
RE: Coding error? - by Mugwash - Apr-04-2018, 04:51 PM
RE: Coding error? - by sparkz_alot - Apr-05-2018, 02:23 PM
RE: Coding error? - by Mugwash - Apr-06-2018, 06:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New to coding. An error occurs with no definition westernwhiskey 4 3,132 Mar-15-2018, 12:37 PM
Last Post: westernwhiskey
  Python Coding Error MGallo 3 3,864 Jul-20-2017, 02:35 PM
Last Post: MGallo

Forum Jump:

User Panel Messages

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