Python Forum
Can not get quiz game to work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can not get quiz game to work
#1
I tried to make a quiz game but one question does not work. it will say well done even if you got it incorrect here is a bit of the code i used on python 3.5.3

turkeycapital=input ("what is the capital of turkey ")
if turkeycapital == "Ankara" or "ankara":
    print ("very smart")
    points=points+1
else:
    ("that was hard")
Reply
#2
Please, read https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I am no admin but you should post your code in Python tags.

Your code if-clause will always evaluate to True therefore you get always if branch.

Why it evaluates to True? You have or condition. If either part of or is True then if-clause is True. String evaluates to True if it is not empty. String is False then it is empty. As 'ankara' is not empty string it always truthy.

>>> if 'ankara':
...     print('this is true')
...
this is true


You can remedy it by writing correctly:

if turkeycapital == "Ankara" or turkeycapital == "ankara":
But more commone way is to convert either lower or uppercase:

if turkeycapital.lower() == 'ankara':
This way you'll cover all caps and typos as well.

And of course, else-clause misses print statement.

And if there is more than one question you should use function.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
You are missing print before ("that was hard")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 707 Aug-25-2023, 08:24 PM
Last Post: deanhystad
  Guessing Game does not work the_entrepreneur 3 2,760 Apr-20-2019, 06:19 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

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