# Noemi Cabrera
# 30 September 2021
# In this lesson, I learned use the elif conditional in if/else statements, which helps to test
# multiple conditions and see which one is true depending on the input. I also practiced casting/
# converting from one data type to another by using int(), str(), and float(). This is important
# because data types can only be added with the same data type, if not, an error will display.
# I did not have any difficulties in this lesson.
# [ This code asks for user input on the weather. The if/else statement is combinated with the
# elif statement to check for the different weather options: sunny, rainy, and snowy.
# Only the condition that is true will display and the others are ignored. ]
# review the code then run testing different inputs
# WHAT TO WEAR
weather = input("Enter weather (sunny, rainy, snowy): ")
if weather.lower() == "sunny":
print("Wear a t-shirt")
elif weather.lower() == "rainy":
print("Bring an umbrella and boots")
elif weather.lower() == "snowy":
print("Wear a warm coat and hat")
else:
print("Sorry, not sure what to suggest for", weather)
# [ This code asks the user to guess a secret number. The if/else statement is combinated with the
# elif statement to check if the user entered a digit, if the user got the secret number, or if
# the number entered was too low or too high. Only the condition that is true will display and the
# others are ignored. ] review the code then run testing different inputs
# SECRET NUMBER GUESS
secret_num = "2"
guess = input("Enter a guess for the secret number (1-3): ")
if guess.isdigit() == False:
print("Invalid: guess should only use digits")
elif guess == "1":
print("Guess is too low")
elif guess == secret_num:
print("Guess is right")
elif guess == "3":
print("Guess is too high")
else:
print(guess, "is not a valid guess (1-3)")
# [This program asks for user input on shirt size to check if the size is available,
# and if available, it displays the cost of the shirt. Only the condition that is true will
# display and the others are ignored. ]
# SHIRT SALE
shirt_size = input("Enter your shirt size (S,M,L): ").capitalize()
if shirt_size == "S":
print("Small = $6")
elif shirt_size == "M":
print("Medium = $7")
elif shirt_size == "L":
print("Large = $8")
else:
print(shirt_size, "is not available.")
# In this code, the 2 variables used have different data types. One is a string and the other
# is an integer. In order to add these variables together they have to be both integers, so the
# int() function is used to convert the variable weight1 into an integer.
weight1 = '60' # a string
weight2 = 170 # an integer
# add 2 integers
total_weight = int(weight1) + weight2
print(total_weight)
# The 3 variables in this code do not have the same data type, so they cannot be added together.
# Therefore, the int()function casts the 2 variables with strings to integers.
str_num_1 = "11"
str_num_2 = "15"
int_num_3 = 10
total = int(str_num_1) + int(str_num_2) + int_num_3
print(total)
# The 3 variables in this code do not have the same data type, so they cannot be added together.
# Therefore, the str()function casts the 1 variable with an integer to a string. The result
# is displayed.
str_num_1 = "11"
str_num_2 = "15"
int_num_3 = 10
total = str_num_1, str_num_2, str(int_num_3)
print(total)
# This program adds 2 variables together. Since str_integer contains a string, it's casted to a
# string by using the function int() so that it can be add with int_number. The total displays.
str_integer = "5"
int_number = 11
number_total = int(str_integer) + int_number
print(number_total)
# [ This code asks for the age of a student. Since input always returns as a string, it's casted
# to an integer so that it can be added with the integer 1. The age of the student next year
# is displayed.] review and run code
student_age = input('enter student age (integer): ')
age_next_year = int(student_age) + 1
print('Next year student will be',age_next_year)
# [ This code also asks for the age of a student. However, the input is casted to an integer
# by putting it inside the int() function. Then, the age entered is added 10 to display
# the age of the student in a decade.] review and run code
# cast to int at input
student_age = int(input('enter student age (integer): '))
age_in_decade = student_age + 10
print('In a decade the student will be', age_in_decade)
# This program asks the user to enter 2 numbers they want to add. Then the input is casted to
# integers so that they can be added to get a result.
# The addition and result is displayed.
first = input("Enter a number:")
second = input("Enter a number you want to add to the previous one: ")
addition = int(first)+ int(second)
print(first,"+",second,"=",addition)