# Chapter 03 Worksheet

1. What is missing from this code? (1 pt)
temperature = float(input("Temperature: ")
if temperature > 90:
print("It is hot outside.")
else:
print("It is not hot out.")

2. Write a Python program that will take in a number from the user and print if it is positive, negative, or zero. Use a proper if/elif/else chain, don't just use three if statements.
3. Write a Python program that will take in a number from a user and print out Success'' if it is greater than -10 and less than 10, inclusive. (1 pt)
4. This runs, but there is something wrong. What is it? (1 pt)
user_input = input("A cherry is a: ")
print("A. Dessert topping")
print("B. Desert topping")
if user_input.upper() == "A":
print("Correct!")
else:
print("Incorrect.")

5. There are two things wrong with this code that tests if x is set to a positive value. One prevents it from running, and the other is subtle. Make sure the if statement works no matter what x is set to. Identify both issues. (2 pts)
x == 4
if x >= 0:
print("x is positive.")
else:
print("x is not positive.")

6. What three things are wrong with the following code? (3 pts)
x = input("Enter a number: ")
if x = 3
print("You entered 3")

7. There are four things wrong with this code. Identify all four issues. (4 pts)
answer = input("What is the name of Dr. Bunsen Honeydew's assistant? ")
if a = "Beaker":
print("Correct!")
else
print("Incorrect! It is Beaker.")

8. This program doesn't work correctly. What is wrong? (1 pt)
x = input("How are you today?")
if x == "Happy" or "Glad":
print("That is good to hear!")

9. Look at the code below. Write your best guess here on what it will print. Next, run the code and see if you are correct. Clearly label your guess and the actual answer. Also, if this or any other example results in an error, make sure to state that an error occurred. While you don't need to write an explanation, make sure you understand why the computer prints what it does. Don't get caught flat-footed when you need to know later. (2 pts)
x = 5
y = x == 6
z = x == 5
print("x=", x)
print("y=", y)
print("z=", z)
if y:
print("Fizz")
if z:
print("Buzz")

10. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts)
x = 5
y = 10
z = 10
print(x < y)
print(y < z)
print(x == 5)
print(not x == 5)
print(x != 5)
print(not x != 5)
print(x == "5")
print(5 == x + 0.00000000001)
print(x == 5 and y == 10)
print(x == 5 and y == 5)
print(x == 5 or y == 5)

11. Look at the code below. Write you best guess on what it will print. Next, run the code and see if you are correct. (2 pts)
print("3" == "3")
print(" 3" == "3")
print(3 < 4)
print(3 < 10)
print("3" < "4")
print("3" < "10")
print( (2 == 2) == "True" )
print( (2 == 2) == True )
print(3 < "3")

12. What things are wrong with this section of code? The programmer wants to set the money variable according to the initial occupation the user selects. (1 pt)
print("Welcome to Oregon Trail!")

print("A. Banker")
print("B. Carpenter")
print("C. Farmer")

user_input = input("What is your occupation? ")

if user_input = A:
money = 100
else if user_input = B:
money = 70
else if user_input = C:
money = 50

print("Great! you will start the game with", money, "dollars.")

﻿