The program should:
- Ask you if it is raining using input()
- If the input is ‘y’, it should output ‘Take an umbrella’
- If the input is ‘n’, it should output ‘You don’t need an umbrella’
Advertisement
Answer
you can do this in several ways:
if input('it is raining now? y/n ') == 'y': print('Take an umbrella') else: print("You don't need an umbrella")
also you can do it in just one line like this which is probabely an advanced way:
print('Take an umbrella' if (input('it is raining now? y/n: ') == 'y') else "You don't need an umbrella")
also you can first save the input in a variable, and then handle it in if blocks
x = input('it is raining now? y/n ') if x.lower() == 'y': print('Take an umbrella') elif x.lower() == 'n': print("You don't need an umbrella") else: print('wrong input')
the x.lower() makes it acceptable even if user inputs Y or N in capital letters.