Basic python and console interaction
3.6.5: Add Comments!
"""this code will ask user imput on what is your name""" first_name = input("Enter your first name: ") middle_name = input("Enter your middle name: ") last_name = input("Enter your last name: ") #the code will write your full name at the end full_name = first_name + " " + middle_name + " " + last_name print(full_name)
3.5.9: Recipe
# first ingredient first_ingredient = input("Enter ingredient 1: ") first_ounces = float(input("Ounces of " + first_ingredient + ": ")) # second ingredient second_ingredient = input("Enter ingredient 2: ") second_ounces = float(input("Ounces of " + second_ingredient + ": ")) #third ingredient third_ingredient = input("Enter ingredient 3: ") third_ounces = float(input("Ounces of " + third_ingredient + ": ")) #how many servings servings = int(input("Number of servings: ")) #print it all out in definition form print ("Total ounces of " + first_ingredient + ": " + str(first_ounces * servings)) print ("Total ounces of " + second_ingredient + ": " + str(second_ounces * servings)) print ("Total ounces of " + third_ingredient + ": " + str(third_ounces * servings))
3.2.7: Undefined Variables
a = 10 print(a) b = 20 print(b) c = 20 print(c) d = a + b print(d) f = 50 e = f + d print(e)
3.3.7: Age
age=input("How old are you?:") print(age) print("You will need this many candles for your birthday cake:") print(age + 1)
3.2.6: Make Some Variables!
greeting = "Hannah is" num = 28 value = "years old!" print(greeting) print(num) print(value)
3.5.4: Fix This Program
instrument = "kazoo" age = 7 print ("I have played the " + instrument + " since I was " + str(age) + " years old.")
3.4.8: Rectangle
length = 10 width = 5 area = length* width perimeter = 2 * (length + width) print(area) print(perimeter)
3.5.8: Rectangle, Part 3
length = int(input("Length: ")) width = int(input("Width: ")) print ("Area: " + str(length * width)) print ("Perimeter: " + str(2 * (length + width)))
3.5.7: Rectangle, Part 2
length= 50 width= 30 print("Area:" + str(length)) print("Perimeter:" + str(width))
3.3.6: Hello <name>
name = input("What is your name?: ") print("hello") print(name)
3.5.6: Introduce Yourself, Part 2
name= "Hannah" age= 14 print("Hi!" + " My name is " + name +" and I am " + str(age) + " years old.")
3.4.5: Add Parentheses
print (2 + 3 * (4 + 8))
3.1.7: Vertical name
print("H") print("a") print("n") print("n") print("a") print("h")
3.1.6: Fix This Program!
print("Hi there!") print("My favorite color is magenta.")
3.1.5: Introduce Yourself
print("My name is Hannah!") print("I like to write python codes.")