2017-10-17 52 views
0

因此,我一直在重新启动脚本。我正在做一个简单的程序,我想有一个选择,例如:如何使用命令重新启动python脚本

print ('would you like to make another calculation') 

choice3 = input(' Choose: [Y], [N]') 

if choice3.lower() == 'y': 
    print ('OK!') 
    time.sleep(3) 

我想重新启动它。如果有人可以帮助我,谢谢......我真的很感激

+0

我会建议使用while循环,而不是重新启动脚本。 [像这样](https://stackoverflow.com/questions/20337489/python-how-to-keep-repeating-a-program-until-a-specific-input-is-obtained) – MisterMystery

回答

2

可以使用loop做到这一点:

while True: 
    print ('would you like to make another calculation') 
    choice3 = input(' Choose: [Y], [N]') 
    if choice3.lower() == 'y': 
     print ('OK!') 
     time.sleep(3) 
    else: 
     break 
+0

这工作完美。谢谢,我真的很感激 – LostRoninYT