2017-10-17 50 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