attempt = 0
answer = "canberra":
while answer != "canberra"
input("what is the capital of Australia: ?")
print(attempt)
我不知道它有什么问题。基本上,任务是编写代码以反复询问用户问题,直到他们得到正确的答案。但是,当我运行我的代码时,即使我正确回答问题,它也会反复询问问题。我可能会用“if”语句来做,但是任务需要使用“while”循环请,如果有人可以帮助!!(尽管不要过于复杂。):)
答案 0 :(得分:1)
attempt += 1
answer
与字符串'canberra'进行比较。此比较返回False
,因为变量answer
内部已经有'canberra'。所以"canberra" != "canberra"
=> False
。answer = "canberra":
行的末尾有一个冒号,但它应位于下一行while answert ...
的末尾。代码:
attempt = 0
answer = ""
correct_answer = "canberra"
while answer != correct_answer:
answer = input("what is the capital of Australia? ")
attempt += 1
print(attempt)
答案 1 :(得分:0)
您正在伪造while语句的括号,并且在堪培拉旁边也有一个“:”。
看看是否有帮助。
attempt = 0
answer = "canberra";
while (answer != "canberra"):
input("what is the capital of Australia: ?")
attempt += 1
console.log(attempt)