vendredi 14 août 2020

How to shorten an if-statement that prints out a sentence when a condition is met

How to shorten an if-statement that prints out a sentence when a condition is met. For instance,

raining = input("Is it raining (yes/no)? ")
if raining == 'yes':
   print("It's raining")

I tried:

print("It's raining" if raining == yes)

But this gives me a syntax error

Aucun commentaire:

Enregistrer un commentaire