I'm making a program to predict the weather, and I need to ask the user a certain question if the answer was 'yes' to a previous question, or ask a different question if the answer was 'no'. How can I execute an input request only if a certain condition is True
.
You're looking for an if statement:
firstresponse = input('first (y/n): ')
if firstresponse == 'y':
secondresponse = input('second: ')
print(firstresponse)
print(secondresponse)
else:
print(firstresponse)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.