我想在这个程序中使用while循环,而不是for循环,但是我不知道如何以及从哪里开始?任何帮助都会很感激的!在
def password():
guessCount = 0
password = input("Anna please enter a password here\n:")
guesser = input("Guesser please enter your name here\n:")
print("Welcome",guesser,"to the Password Guessing Game.\nYou have 8 attempts to guess my password.\nGood Luck!")
for count in range (8):
passwordGuess = input("Guess the password\n:")
if passwordGuess == password:
guessCount = guessCount + 1
print("Well Done!")
print("It took you",guessCount,"attempt(s) to guess the password!")
break
else:
guessCount = guessCount + 1
print("Try again")
如果你想做类似于for循环的事情,你可以写这样的东西。在
这将对范围(8)中的x执行相同的操作。在
相关问题 更多 >
编程相关推荐