# [ ] complete rainbow colors
rainbow_color = input('What is your favorite color? (red, orange, yellow, green, blue, purple, indigo, or violet)')
if rainbow_color.lower() == 'red':
print("your favorite color is red")
elif rainbow_color.lower() == 'orange':
print("your favorite color is orange")
elif rainbow_color.lower() == 'yellow':
print("your favorite color is yellow")
elif rainbow_color.lower() == 'green':
print("your favorite color is green")
elif rainbow_color.lower() == 'blue':
print("your favorite color is blue")
elif rainbow_color.lower() == 'purple':
print("your favorite color is purple")
elif rainbow_color.lower() == 'indigo':
print("your favorite color is indigo")
elif rainbow_color.lower() == 'violet':
print("your favorite color is violet")
else:
print("please enter a valid color")
# [ ] make the code above into a function rainbow_color() that has a string parameter,
# get input and call the function
def rainbow_color(x):
if x.lower() == 'red':
print("your favorite color is red")
elif x.lower() == 'orange':
print("your favorite color is orange")
elif x.lower() == 'yellow':
print("your favorite color is yellow")
elif x.lower() == 'green':
print("your favorite color is green")
elif x.lower() == 'blue':
print("your favorite color is blue")
elif x.lower() == 'purple':
print("your favorite color is purple")
elif x.lower() == 'indigo':
print("your favorite color is indigo")
elif x.lower() == 'violet':
print("your favorite color is violet")
else:
print("please enter a valid color")
color = input('What is your favorite color? (red, orange, yellow, green, blue, purple, indigo, or violet)')
rainbow_color(color)
# [ ] complete age_20()
def age_20(y):
print(int(y) + 20)
number = input("please enter a number")
age_20(number)
# [ ] create rainbow_or_age()
def both(y):
if y.isdigit():
print(int(y) + 20)
elif y.isalpha():
def rainbow_color(x):
if x.lower() == 'red':
print("your favorite color is red")
elif x.lower() == 'orange':
print("your favorite color is orange")
elif x.lower() == 'yellow':
print("your favorite color is yellow")
elif x.lower() == 'green':
print("your favorite color is green")
elif x.lower() == 'blue':
print("your favorite color is blue")
elif x.lower() == 'purple':
print("your favorite color is purple")
elif x.lower() == 'indigo':
print("your favorite color is indigo")
elif x.lower() == 'violet':
print("your favorite color is violet")
else:
print("please enter a valid color")
else:
print("pick one of the options")
question = input("either a number or say your favorite color")
both(question)
color = input('What is your favorite color? (red, orange, yellow, green, blue, purple, indigo, or violet)')
both(color)
# [ ] add 2 numbers from input using a cast to integer and display the answer
number1 = input("print a number")
number2 = input("print a second number")
print(int(number1) + int(number2))
# [ ] Multiply 2 numbers from input using cast and save the answer as part of a string "the answer is..."
# display the string using print
num1 = input("pick a number")
num2 = input("pick a second number")
combination = int(num1) * int(num2)
phrase = "the answer is"
print(phrase, combination)
# [ ] get input of 2 numbers and display the average: (num1 + num2) divided by 2
num1 = input("pick a number")
num2 = input("pick a second number")
combination = int(num1) + int(num2)
combination = combination / 2
phrase = "the average is"
print(phrase, combination)
# [ ] get input of 2 numbers and subtract the largest from the smallest (use an if statement to see which is larger)
# show the answer
num1 = input("pick a number")
num2 = input("pick a second number")
if num1 > num2:
print(int(num2) - int(num1))
elif num2 > num1:
print(int(num1) - int(num2))
else:
print("please enter a valid number")
# [ ] Divide a larger number by a smaller number and print the integer part of the result
# don't divide by zero! if a zero is input make the result zero
# [ ] cast the answer to an integer to cut off the decimals and print the result
num1 = input("pick a number but not 0")
num2 = input("pick a second number that is not 0")
if num1 > num2:
print(int(num1) / int(num2))
elif num2 > num1:
print(int(num2) / int(num1))
else:
print("please enter a valid number")