-3

所以我正在做一个测验,当我if在 python 中做一个陈述来提出一个问题时,我必须把它放在它之前(我在答案中使用它)。if所以我的问题是如何在不停止声明的情况下让它发生。任何想法表示赞赏。抱歉,如果很难知道我想说什么,我对 python 有点陌生。

4

2 回答 2

2

可能是这样的?

answer = input ('Who was the last king of Rome? ') #use raw_input for python2.x
if answer == 'Tarquinius': print ('correct')
else: print ('incorrect')
于 2013-09-21T05:49:51.293 回答
0
print 'asdf' if 1 == 2 else 'fdsa'

或者,如果你不明白这一点,试试这个:

print "ok..nice" if raw_input("how are you ") == "ok" else "well, that's too bad"

显然人们不知道新的内联if语法,并认为我在拖钓。

这应该都写在 1 行中,不需要拆分。

于 2013-09-21T06:04:10.673 回答