如何重新启动我的python程序的顶部 [英] How to restart to the top of my program for python

查看:55
本文介绍了如何重新启动我的python程序的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,在我的程序结束时,我问用户'是全部',当用户输入'不'时,我希望程序再次启动,这样用户可以再次通过程序,但我不确定怎么做







导入itertools

导入时间

导入系统

刹车= [刹车,不是,正在工作,踏板]

转向= [转向, 轮,卡住,不会,转

无效=真

无效==真:

brakes_counter = 0

steering_counter = 0

错误=输入(你的车有什么问题)。lower()

问题= error.split()

for i in problem:

如果我在刹车:

brakes_counter + = 1

无效=错误

elif我在转向:

steering_counter + = 1

无效=错误

否则:

打印(再试一次)

打破

打开('brakesandsteering' .txt',r)as text_file:

if brakes_counter> steering_counter:

for itertools.islice(text_file,0,22):

打印(行)



elif steering2> brakes2:

for itertools.islice(text_file,24,46) :

打印(行)

isthatall =输入(就是全部?是/否)。lower()

if isthatall = =是:

打印(\ n谢谢你使用我的程序)

sys.exit()

elif isthatall = =不:

#i希望它在这里重新开始

thi s是不起作用的地方

而isthatall!=no和isthatall!=是:

time.sleep(1)

打印(再试一次)

time.sleep(1)

isthatall = input(就是全部?是/否)。 lower()

In this case at the end of my program I ask the user 'is that all' and when the user inputs 'no' I want the program to start again so the user can go through the program again however I am not sure how to do this



import itertools
import time
import sys
brakes=["brakes","not","working","pedal"]
steering=["steering","wheel","stuck","won't","turn"]
invalid=True
while invalid==True:
brakes_counter=0
steering_counter=0
wrong=input("What is wrong with your car").lower()
problem = wrong.split()
for i in problem:
if i in brakes:
brakes_counter +=1
invalid=False
elif i in steering:
steering_counter +=1
invalid=False
else:
print("try again")
break
with open('brakesandsteering.txt',"r") as text_file:
if brakes_counter>steering_counter:
for line in itertools.islice(text_file,0,22):
print(line)

elif steering2>brakes2:
for line in itertools.islice(text_file,24,46):
print(line)
isthatall = input("is that all?yes/no").lower()
if isthatall== "yes":
print("\nThank you for using my program")
sys.exit()
elif isthatall == "no":
#i want it to go to the start again here
this is where it does not work
while isthatall != "no" and isthatall !="yes":
time.sleep(1)
print("try again")
time.sleep(1)
isthatall=input("is that all?yes/no").lower()

推荐答案

使用某种形式的循环控制,例如 while [ ^ ]。
Use some form of loop control such as while[^].


import itertools
import time
import sys
brakes=["brakes","not","working","pedal"]
steering=["steering","wheel","stuck","won't","turn"]
#
# the main loop of processing starts here
# 
isthatall = "no"
while isthatall == "no":
    ' do your other processing
    isthatall=input("is that all?yes/no").lower()


这篇关于如何重新启动我的python程序的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆