我写了几个定义,我希望用户选择要运行的定义,但定义总是打印如何打开和定义?如果用户选择 2,则不应打印。我错过了什么?Senerio = 0while Senerio not in (1, 2, 3, 4): Senerio = int(input("choose a commission/Aggregation senerio number \n" "1. put in car \n" "2. put in plane \n" "3. put on boat \n" "4. put on fire "))if Senerio == 1:Car = 1Plane = 0boat = 0fire = 0def incar(): print('Im putting this in a car')incar()if car == 1: incar
2 回答
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
这应该可以解决它
Senerio = 0
while Senerio not in (1, 2, 3, 4):
Senerio = int(input("choose a commission/Aggregation senerio number \n"
"1. put in car \n"
"2. put in plane \n"
"3. put on boat \n"
"4. put on fire "))
if Senerio == 1:
car = 1
plane = 0
boat = 0
fire = 0
def incar():
print('Im putting this in a car')
if car == 1:
incar()
MM们
TA贡献1886条经验 获得超2个赞
我发现将我的if语句包裹在定义周围给了我想要的东西,就像这样:
if car == 1:
def incar():
print('Im putting this in a car')
incar()
incar
添加回答
举报
0/150
提交
取消