我如何在条件后要求用户输入?

问题描述 投票:-5回答:1

我正在编写一个预测天气的程序,我需要向用户询问某个问题,如果答案是对上一个问题的“是”,或者询问另一个问题,如果答案是“否”。仅当特定条件为True时,才能执行输入请求。

python input
1个回答
0
投票

您正在寻找一个if语句:

firstresponse = input('first (y/n): ')

if firstresponse == 'y':
  secondresponse = input('second: ')
  print(firstresponse)
  print(secondresponse)
else:
  print(firstresponse)
© www.soinside.com 2019 - 2024. All rights reserved.