我的if语句有问题;没有输出或错误



保留部分未打印我没有收到错误或类似的东西

#TEXT SECTION
#Start
textMorn= "It's 8 in the morning, the sunshine comes up and you slowly open your eyes. You realize it's monday morning, so you get up and start making some breakfast. You munch down a nice bowl of cereal, consisting of mini wheats and milk. Once it's finished , you wash the bowl and spoon and brush your teeth. You check the time while brushing your teeth and see that it's 8:27, and you woke up an hour later than you were supposed to. You don’t want to be late for school, so you think about taking public transit. It is a little pricey though, because you need to save up for public transit after school so you can get home earlier. You can also walk to school, but you will be 10 minutes late. What do you choose? Type WALK or TRANSIT."
morn1=str(input(textMorn))
#First Choice
textWalk=("You walk to school, and it's a long walk since you live 25 minutes away. You come to class late, and everyone is looking at you when you walk in. It doesn't matter though, since you still got to class. Your first period is math, and during the lesson 30 minutes in, and all the sudden you feel like you need to go to the washroom to take a big dump. You really don't want to skip 15 minutes worth of class, but you feel really bad right now. Do you want to get to the washroom, or hold it in for the rest of class. Type HOLD or GO.")
walk=str(textWalk)
textTransit=str("You take public transit, even though it means that you can't get home early. You go to the bus stop and wait for a few minutes. 3 minutes later, a bus comes by, you get on and get to school in 10 minutes. You come to class just on time. Your first period is math, and during the lesson 40 minutes in, and all the sudden you feel like you need to go to the washroom to take a big dump. You really don't want to skip 15 minutes worth of class, but you feel really bad right now. Do you want to get to the washroom, or hold it in for the rest of class.Type HOLD or GO.")
transit=str(textWalk)
#Second Choice
go=("""You ask the teacher to go to the bathroom, and he allows you to go right away. You walk across the halls and go to the washroom. When you step in, it reeks of smoke. You realize there is people vaping in the bathroom, so you go to the sinks and check, and unsurprisingly you see 2 guys that look like seniors vaping at the sinks. You can either ignore them or tell them to get out of the washroom. Type IGNORE or TELL.""")
goText=str(go)
golate1=str("""You ask the teacher to go to the bathroom, and he reluctantly allows you to go right away since you were already late for class. You walk across the halls and go to the washroom. When you step in, it reeks of smoke. You realize there's people vaping in the bathroom, so you go to the sinks and check, and unsurprisingly you see 2 guys that look like seniors vaping at the sinks. You can either ignore them or tell them to get out of the washroom. Type IGNORE or TELL.""")
holdText=("""You hold it in and try to focus on class, but you didn't get any further than expected. Class ends, and you rush to the washroom. Once you’re done with your business, you go to the next class 5 minute late and get through english class. Lunch time starts and you get a call from your mom, telling you to stop being late to class all the time. You simply ignore her, since you feel like there was nothing you could do about it. Now it's time to focus on lunch. You feel like you don’t really want to talk to anyone, but you don't want to ditch your friends during lunch. What do you choose, lunch alone or with your friends? Type FRIENDS or ALONE.""")
hold1=str(holdText)
print("line 67")
if morn1=="TRANSIT":
input(transit)
if transit=="HOLD":
input(hold1)
if morn1=="WALK":
input(walk)
if walk=="GO":
input(go)

问题是input(transit)不会更改transit;它只是显示transit作为输入提示,但随后丢弃用户键入的任何内容。您必须将输入语句的输出存储在一个变量中。最简单的修复方法是用transit = input(transit)替换该行,但更好的修复方法将结果保存在不同的变量中:

if morn1=="TRANSIT":
transit_input = input(transit)
if transit_input =="HOLD":
input(hold1)

顺便说一句,如果你不想键入所有大写的内容,你可以通过将所有内容转换为相同的大小写来进行不区分大小写的比较:

if morn1.lower() == "transit":
transit_input = input(transit)
if transit_input.lower() == "hold":
input(hold1)

最新更新