-1
我想在此程序中使用while循环而不是for循环,但我不知道如何以及从何处开始?任何帮助将被赞赏!Python中的循环
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")
欢迎来到Stack Overflow :)这是什么语言?请为该语言添加标签。另外,你为什么要在这里使用'while'循环? – 2014-10-09 17:46:05
如果你搜索“用户输入while循环”,你会发现一般的模式。你甚至可以用你正在使用的语言找到它。 – 2014-10-09 17:48:45
我不知道你为什么想要这样做,但是你可以直接用while来替换单词,并在循环前有一个“count = 0”,它将全部工作。 – Spade 2014-10-09 18:05:55