Can not get quiz game to work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Can not get quiz game to work (/thread-15850.html) |
Can not get quiz game to work - funkymonkey123 - Feb-03-2019 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") RE: Can not get quiz game to work - buran - Feb-03-2019 Please, read https://python-forum.io/Thread-Multiple-expressions-with-or-keyword RE: Can not get quiz game to work - perfringo - Feb-03-2019 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. RE: Can not get quiz game to work - chesschaser - Jul-02-2020 You are missing print before ("that was hard") |