我如何打印在壳的底部没有重新排序代码?(Python3)



问题示例:

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!')

有一个简单的方法可以解决这个问题。

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)

最新更新