首页 > 解决方案 > 我的部分代码在 while 循环中不起作用

问题描述

我不知道为什么,但它是在猜测密码,但是当它猜对时它并没有结束程序。任何帮助深表感谢!

#imports
import time, random

#Welcome
print("Welcome to Password Guess!")
pass1 = input("Please insert your phone password:")

#Start system

guessclock = 0

start1 = 1

i = 1
while i < 2:
    while i < 2:
        guess1 = random.randint(1, 2)
        guessclock += 1
        print(guess1)
    if pass1 == guess1:
        i = 3
        print("Password guessed")
        print("It took", guessclock)
        print("Attempts")

标签: pythonpython-3.xloops

解决方案


尝试更换

pass1 = input("Please insert your phone password:")

pass1 = int(input("Please insert your phone password:")) # turns pass1 into an integer

推荐阅读