while loop - where have i went wrong with my code? -
attempt = 0 answer = "canberra": while answer != "canberra" input("what capital of australia: ?") print(attempt)
i don't know whats wrong it. basically, task write code repeatedly ask user question until answer correct. however, when run code, repeatedly asks question when answer question correctly. able "if" statements task requires use "while" loops please, if can, help!!(don't on complicate though.) :)
loops
- it's unclear programming language use. think it's python :)
- you should increment attempts counter in while loop this:
attempt += 1
- in beginnig of while loop comparing variable
answer
string 'canberra'. comparsion returnsfalse
because variableanswer
have 'canberra' inside."canberra" != "canberra"
=>false
. - you have colon @ end of line
answer = "canberra":
, should @ end of next linewhile answert ...
.
the code:
attempt = 0 answer = "" correct_answer = "canberra" while answer != correct_answer: answer = input("what capital of australia? ") attempt += 1 print(attempt)
Comments
Post a Comment