Python Forum

Full Version: Can not get quiz game to work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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")
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.
You are missing print before ("that was hard")