More Practice with Variables and Logic Check
You will be getting more practice declaring and manipulating variables, and checking logic in this exercise.
Starter file
# Declare a variable of `name` with an input and a string of "Welcome to the Boba Shop! What is your name?".
# Check if `name` is not an empty string or equal to `None`.
# If so, write a print statement with a string of "Hello" concatenated with the variable `name`.
# Then, declare a variable of `beverage` with an input and a string of "What kind of boba drink would you like?".
# Then, Declare a variable of `sweetness_level` with an input and a string of "How sweet do you want your drink: 0, 50, 100, or 200?".
# If `sweetness` equals 50 print "half sweetened".
# Else if `sweetness` 100 print "normal sweet".
# Else if `sweetness` 200 print "super sweet".
# Else print with a string of "non-sweet".
# Then print the string of "Your order of " concatenated with the variable `beverage`, concatenated with " boba with a sweet level of ", concatenated with the variable `sweetness`
# Else, print the string of "You didn't give us your name! Goodbye"
Instructions
Perform the following:
- Declare a variable of
namewith an input and a string of “Welcome to the Boba Shop! What is your name?” - Check if
nameis not an empty string or equal toNone.- If so, write a print statement with a string of “Hello” concatenated with the variable
name. - Declare a variable of
beveragewith an input and a string of “What kind of boba drink would you like?” - Declare a variable of
sweetness_levelwith an input and a string of “How sweet do you want your drink: 0, 50, 100, or 200?”- If
sweetness_levelequals 50, declare a variablesweetnessas “half sweetened”. - Else if
sweetness_levelequals 100, declare a variablesweetnessas “normal sweet”. - Else if
sweetness_levelequals 200, declare a variablesweetnessas “super sweet”. - Else, declare a variable
sweetnesswith a string of “non-sweet”.
- If
- Print the string of “Your order of ” concatenated with the variable
beverage, concatenated with ” boba with a sweet level of “, concatenated with the variablesweetness.
- If so, write a print statement with a string of “Hello” concatenated with the variable
- Else, print the string of “You didn’t give us your name! Goodbye”.
HINT: Remember to cast your numerical values as int()
Solution
# Declare a variable of `name` with an input and a string of "Welcome to the Boba Shop! What is your name?".
name = input("Welcome to the Boba Shop! What is your name?")
# Check if `name` is not an empty string or equal to `None`.
if name != "" or name == None:
# If so, write a print statement with a string of "Hello" concatenated with the variable `name`.
print(f"Hello {name}")
# Then, declare a variable of `beverage` with an input and a string of "What kind of boba drink would you like?".
beverage = input("What kind of boba drink would you like?")
# Then, Declare a variable of `sweetness` with an input and a string of "How sweet do you want your drink: 0, 50, 100, or 200?".
sweetness_level = int(input("How sweet do you want your drink: 0, 50, 100, or 200?"))
# If `sweetness` equals 50 print "half sweetened".
if sweetness_level == 50:
sweetness = "half sweetened"
# Else if `sweetness` 100 print "normal sweet".
elif sweetness_level == 100:
sweetness = "normal sweet"
# Else if `sweetness` 200 print "super sweet".
elif sweetness_level == 200:
sweetness = "super sweet"
# Else print with a string of "non-sweet".
else:
sweetness = "non-sweet"
# Then print the string of "Your order of " concatenated with the variable `beverage`, concatenated with " boba with a sweet level of ", concatenated with the variable `sweetness`
print(f"Your order of {beverage} boba with a sweetness level of {sweetness}")
# Else, print the string of "You didn't give us your name! Goodbye".
else:
print("You didn't give us your name! Goodbye")