Module 3 Lab 2 Solution
Welcome to our Lab Practice!
This lab is about branching - if-else statements4 Are you ready? Let's get started!
You will find some small tasks in sections below4
###Task@ Check if the weather is good for hiking4
You should ask the user to enter a float value as the temporature in Fahrenheit4
If the temporature is within FGHI JHKI print "Perfect"N
otherwiseI print "Not that good"4
temp = float(input('Please enter the temporature in Fahrenheit: '))
if temp < 60 or temp > 80:
print('Not that good')
else:
print('Perfect')
###Task@ Check if the user feels happy
You should ask the user "Are you happy now?"4
If the user enters "Yes"I print "Fantastic!"
otherwiseI print "How can I help?"
happy = input('Are you happy now? Yes or No:')
if happy == 'Yes':
print('Fantastic!')
else:
print('How can I help?')
Are you happy now? Yes or No:Yes
Fantastic!
###Task@ check if your plants need water
You should ask the user to enter an integer indicating the level of moisture of the soil (from VY super dryN
to VHY super wet)4
If the level is below [I print "YesI you should water your plants now"
otherwiseI print "No4 Wait for the soil to be dryer"4
level = int(input('Enter the level of moisture of the soil(from 1: super dry; to 10: super wet
if level < 3:
print('Yes, you should water your plants now')
else:
print('No. Wait for the soil to be dryer')
###Task@ check if a student finished LabT
At firstI ask the user@ "Do you care about your learning outcome?"
If yesI ask the user "Have your finished M[LabT?"
** if yesI print "Good job!" ** If noI print "Get it done ASAP!!!!!!"
If noI then print "As long as you are happy4"
care = input('Do you care about your learning outcome? Yes or No:')
if care == 'Yes':
finish = input('Have your finished M3Lab2? ')
if finish == 'Yes':
print('Good job!')
else:
print('Get it done ASAP!!!!!!')
else:
print('As long as you are happy.')
Do you care about your learning outcome? Yes or No:Yes
Have your finished M3Lab2? Yes
Good job!