Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从else语句重新启动代码?_Python_Python 3.x_If Statement - Fatal编程技术网

Python 如何从else语句重新启动代码?

Python 如何从else语句重新启动代码?,python,python-3.x,if-statement,Python,Python 3.x,If Statement,这里有一些我一直在编写的代码(Python3.4),我不知道如何在else语句之后重新启动程序。我知道没有goto语句 我试着把if语句放在while-true循环中,但它只是循环print行,反复打印输出 随机导入 导入字符串 PassGen=“” length=int(输入(“您希望您的密码包含8-15个字符?”) 如果8你很接近虽然为True可以,但您还需要一个中断来摆脱它: while True: length = int(input("how many characters w

这里有一些我一直在编写的代码(Python3.4),我不知道如何在
else
语句之后重新启动程序。我知道没有
goto
语句

我试着把
if
语句放在
while-true
循环中,但它只是循环
print
行,反复打印输出

随机导入
导入字符串
PassGen=“”
length=int(输入(“您希望您的密码包含8-15个字符?”)

如果8你很接近
虽然为True
可以,但您还需要一个
中断
来摆脱它:

while True:
    length = int(input("how many characters would you like in your password"))
    if 8 <= length <=15:
        while len(PassGen) != length:
            Num1 = random.choice(string.ascii_uppercase)
            Num2 = random.choice(string.ascii_lowercase)
            Num3 = random.choice(string.digits)
            everything = [Num1, Num2, Num3]
            PassGen += random.choice(everything)
        print (PassGen)
        break
    else:
        print ("that is an incorrect value")
为True时:
length=int(输入(“您希望密码中包含多少字符”))

if 8您可以使用
而true:
循环和
根据需要从
if and else语句中断开
循环。这可能是对的一半。我不得不将长度语句放入While循环中,但感谢您的帮助