Previous Lecture Lec 6 Next Lecture

Lec 6, Wed 01/22

Thursday Lecture 06 Notes

Announcements:

Review

Questions:

Using Conditionals

Example:


raining = input("is it raining? [y/n] ")

if (raining == 'y')
    print("It is raining")
    
elif (raining == 'n'):
    print('it is not raining')

else:
    print("not an option")
    

if you wanted to be able to use other inputs (e.g., 'y' 'yes' 'Y') to be able to output “It is raining”, you would do so by changing the comparison in the conditional like this:


if (raining == 'y' or raining == 'Y' or raining == 'yes'):
    print("It is raining")
    

Q: could we get around this by putting all possible conditionals in a list or something and then use an in statement??? A: Yes!


if raining in ('y','Y','yes'):
    print("It is raining")
    

Q:

We posted a follow-up about it on Piazza: https://piazza.com/class/k54kv5vmxdu67o?cid=41.