Conditions in python code HS questions
and answers 100% pass
4.1.4: Fix This Program ✔✔brought_food = True
brought_drink = False
print(brought_food)
print(brought_drink)
# These lines don't work! Fix them so that t
...
Conditions in python code HS questions
and answers 100% pass
4.1.4: Fix This Program ✔✔brought_food = True
brought_drink = False
print(brought_food)
print(brought_drink)
# These lines don't work! Fix them so that they do.
print(type ("Did the person bring food? " + str(brought_food)))
print(type ("Did the person bring a drink? " + str(brought_drink)))
4.1.5: Plants ✔✔needs_water = True
needs_to_be_repotted = False
print("Needs water: " + str(needs_water))
print (str(needs_to_be_repotted))
print(needs_water)
4.2.5: Fix This Program ✔✔can_juggle = True
# The code below has problems. See if
# you can fix them!
if can_juggle:
print("I can juggle!")
else:
print("I can't juggle.")
4.2.6: Is It Raining? ✔✔
4.3.6: Old Enough to Vote? ✔✔your_age = int(input("How old are you?: "))
age_requirement= 18
can_vote = your_age >= age_requirement
if can_vote:
print("old enough to vote")
else:
print("not old enough to vote")
4.3.7: Positive, Zero, or Negetive ✔✔random_number = int(input("Enter a number: "))
if random_number < 0:
print("That number is negative!")
elif random_number > 0:
print("That number is positive!")
else:
print("That number is zero!")
4.3.9: Table Reservation ✔✔reservation_name = "Shonda"
name = input("Name: ")
if name == reservation_name:
print ("Right this way!")
else:
print ("Sorry, we don't have a reservation under that name.")
4.3.10: Transaction ✔✔# This program simulates a single transaction -
# either a deposit or a withdrawal - at a bank.
print(1000-50)
print(1000+150)
print("Invalid transaction")
print("You cannot have a negative balance!")
4.4.4: Administrators, Teachers and students ✔✔role = input("Are you an administrator, teacher,
or student? ")
if role == "teacher" or role == "administrator":
print ("Administrators and teachers get keys!")
elif role == "student":
print ("Students do not get keys!")
else:
print ("You can only be an administrator, a teacher, or a student!")
4.4.5: Presidential Eligibility ✔✔age = int(input("Age: "))
if age >= 35:
print ("You are eligible to run for president.")
else:
print ("You are not eligible to run for president.")
4.4.6: Presidential Eligibility extended ✔✔age = int(input("Age: "))
citizen = input("Born in the U.S.? (Yes/No): ")
years_resident = int(input("Years of Residency: "))
if age >= 35 and citizen == "Yes" and years_resident >= 14:
print ("You are eligible to run for president!")
else:
print ("You are not eligible to run for president.")
if age < 35:
print("You are too young. You must be at least 35 years old.")
if citizen == "No":
print ("You must be born in the U.S. to run for president.")
if years_resident < 14:
print ("You have not been a resident for long enough.")
4.5.4: Correct Portion ✔✔# Amount of food and number of people
tons_of_food = 0.07
num_people = 25
# Determine how much food each person gets
tons_of_food_per_person =round(tons_of_food)/ round(num_people)
print(tons_of_food_per_person)
# Ask the user how much food they took
tons_taken = float(input("How many tons of food did you take? "))
if round(tons_taken, 5) == round(tons_of_food_per_person, 5):
print ("Good job, you took the right amount of food!")
else:
print ("You took the wrong amount of food
[Show More]