这个程序要求用户猜测数字,它会一直问用户猜测数字,直到他们正确猜测为止。一旦他们正确地猜到了,它就会告诉他们多少次尝试过。
answer = 10
attempts= 0
userentry=""
#a loop that repeats while the users guess is not the same as the answer
# 当用户猜测与答案不同时重复的循环
while answer != userentry:
userentry = int(input("Enter a number between 1 and 20 :"))
#each time through the loop 1 is added to the number of attempts
# 每次通过循环1都被添加到尝试次数
attempts=attempts+1
#after the loop it will say how many attempts it took
# 循环之后,它将显示它尝试了多少次
print("Well done you correctly guessed the number it took you " + str(attempts) + " attempts")