Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Can not get quiz game to work
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")
    ("that was hard")
buran wrote Feb-03-2019, 12:02 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, read
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

Life of Brian: Conjugate the verb, "to go" !

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Guessing Game does not work the_entrepreneur 3 216 Apr-20-2019, 06:19 AM
Last Post: SheeppOSU
  Grabbing questions from a quiz app CodingUnicorn 0 222 Mar-05-2019, 11:26 PM
Last Post: CodingUnicorn
  New to MySQL, can't work out why code doesn't work kintarowonders 6 394 Feb-18-2019, 05:23 PM
Last Post: kintarowonders
  Python Music Quiz lynden 6 4,619 Nov-12-2018, 12:31 PM
Last Post: Tashbf
  Bubble sort quiz: why the result is not the same? lupoalberto 11 1,595 Apr-27-2018, 12:18 PM
Last Post: ljmetzger
  Help with Quiz Learning2teach 1 1,264 May-23-2017, 08:11 PM
Last Post: Ofnuts

Forum Jump:

Users browsing this thread: 1 Guest(s)