如何在不重新排序代码的情况下在shell底部打印? (Python3)

时间:2011-11-26 22:10:58

标签: python-3.x

我的问题示例:

food_choice=input("Would you like to eat a burrito or a pizza? ")

if food_choice=='burrito':

    print('You should go to a Mexican restaurant!')

if food_choice=='pizza':

    print('You should go to an Italian restaurant!')

    print('Don't forget to save me a slice of pizza!') #<----- How do I print this at the bottom?


print('Everyone loves to eat!')

print('Have a good time at your restaurant!')

1 个答案:

答案 0 :(得分:1)

这是解决此问题的简单方法。

after = ""
food_choice=input("Would you like to eat a burrito or a pizza? ")
if food_choice=='burrito':
    print('You should go to a Mexican restaurant!')
if food_choice=='pizza':
    print('You should go to an Italian restaurant!')
    after = 'Don't forget to save me a slice of pizza!'

print('Everyone loves to eat!')

print('Have a good time at your restaurant!')
if after:
    print(after)