Flow with Conditionals
Briefing:
Now you know the basics it’s time to teach you one of the most useful things in programming, conditionals. Using “if statements” you can get a program to be dynamic and flow the way you want it to, based on the information it receives. If you’re ready, let’s go!
Hint:
Using the examples, try to create the if/elif/else logic for Challenge 1.
You can re-use most of your code from Challenge 1 in the other two challenges.
Code Solution:
The following code is the solution to this challenge. Please note that there may be alternative ways to complete this challenge.
# CHALLENGE 1: Check if the number of people is lower than the capacity.
# If it is, print "success"
# If the number of people is higher than the capacity,
# print "too full"
# If the number of people is equal to the capacity,
# print "maximum people"
if people < capacity:
print("success")
elif people > capacity:
print("too full")
elif people == capacity:
print("maximum people")
# CHALLENGE 2: Set the value of the people variable to 500.
# Then run the same check from CHALLENGE 1 again.
people = 500
if people < capacity:
print("success")
elif people > capacity:
print("too full")
elif people == capacity:
print("maximum people")
# CHALLENGE 3; Set the value of the people variable to 50.
# Then run the same check from CHALLENGE 1 again.
people = 50
if people < capacity:
print("success")
elif people > capacity:
print("too full")
elif people == capacity:
print("maximum people")