my_pet = "Garfield"
your_pet = my_pet
my_pet = "Snoopy"
print(f"my pet is {my_pet}")
my pet is Snoopy
my_pet = "Garfield"
your_pet = my_pet
my_pet = "Snoopy"
print(f"your pet is {your_pet}")
your pet is Garfield
del your_pet
my_pet = "Garfield"
my_pet = your_pet
your_pet = "Snoopy"
print(f"your pet is {your_pet}")
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /tmp/ipykernel_363221/3736543107.py in <module> 1 my_pet = "Garfield" ----> 2 my_pet = your_pet 3 your_pet = "Snoopy" 4 print(f"your pet is {your_pet}") NameError: name 'your_pet' is not defined
left_cup = "Nothing"
middle_cup = "A ball"
right_cup = "Nothing"
left_cup = right_cup
left_cup = middle_cup
print(f"The left cup contains {left_cup}")
print(f"The middle cup contains {middle_cup}")
print(f"The right cup contains {right_cup}")
The left cup contains A ball The middle cup contains A ball The right cup contains Nothing
left_cup = "Nothing"
middle_cup = "A ball"
right_cup = "Nothing"
left_cup = middle_cup
middle_cup = right_cup
print(f"The left cup contains {left_cup}")
print(f"The middle cup contains {middle_cup}")
print(f"The right cup contains {right_cup}")
The left cup contains A ball The middle cup contains Nothing The right cup contains Nothing
left_cup = "Nothing"
middle_cup = "A ball"
right_cup = "Nothing"
left_cup = middle_cup
middle_cup = right_cup
right_cup = left_cup
print(f"The left cup contains {left_cup}")
print(f"The middle cup contains {middle_cup}")
print(f"The right cup contains {right_cup}")
The left cup contains A ball The middle cup contains Nothing The right cup contains A ball
left_cup = "Nothing"
middle_cup = "A ball"
right_cup = "Nothing"
left_cup = middle_cup
middle_cup = right_cup
left_cup = right_cup
print(f"The left cup contains {left_cup}")
print(f"The middle cup contains {middle_cup}")
print(f"The right cup contains {right_cup}")
The left cup contains Nothing The middle cup contains Nothing The right cup contains Nothing
# Prompt the user to enter a number
num = float(input("Enter a number:"))
# Check if the number is positive
if num > 0:
print("The number is positive.")
print(num, "is greater than zero")
print("The number was ", num)
Enter a number:-2 The number was -2.0
num = int(input("Enter an integer: "))
if num % 2 == 0:
print(num, "is even.")
else:
print(num, "is odd.")
Enter an integer: 4 4 is even.
score = int(input("Enter your score: "))
if score >= 85: print("Excellent")
elif score >= 60: print("Pass")
else: print("Fail")
Enter your score: 61 Pass
num = float(input("Enter the first number: "))
if num > 5:
print(num, "is greater than 5.")
elif 5 > num:
print(num, "is less than 5.")
else:
print(num, "is equal to 5.")
Enter the first number: 4 4.0 is less than 5.
score = int(input("Enter your score: "))
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
elif score >= 60:
print("D")
else:
print("F")