Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我对我的if声明有异议;没有输出或错误_Python_If Statement_Statements - Fatal编程技术网

Python 我对我的if声明有异议;没有输出或错误

Python 我对我的if声明有异议;没有输出或错误,python,if-statement,statements,Python,If Statement,Statements,暂停部分未打印 我没有得到一个错误或类似的东西 #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 c

暂停部分未打印 我没有得到一个错误或类似的东西

#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)

问题是
输入(传输)
不会改变
传输
;它只显示
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)

您没有从
input(transit)
任何地方对输入进行辅助;你可能想做
transit=input(textTransit)
或类似的事情-因为你正在检查它下面的
transit
的内容。transit是“youtake…”,你永远不会更改它,所以if总是假的。好吧,我试过了,它正在工作!为了澄清,我应该将旧变量放入一个新变量中,这样它就可以打印,对吗?
hold1
从未打印的原因是
transit==“HOLD”
不可能是
True
,因为
transit
从未被设置为
str(textweak)
之外的任何值。因此,为了使该条件实际为
True
(因此打印
hold1
的代码将执行),您必须将用户的输入存储在
transit
中,以便
if
语句工作,或者将输入存储在另一个变量中(在我的示例中,我使用了
transit\u input
),并更改
if
语句以检查该变量。