3.6 & 3.7 Homework Hacks
Homework 3.6 & 3.7
Homework 3.6
import sys
def question_with_response(prompt):
answer = input(prompt)
return answer
questions = 5
correct = 0
user_name = question_with_response("Enter your name: ")
print(f'Hello, {user_name}! You are running Python using {sys.executable}.')
ready = question_with_response("Are you ready to take a sports quiz? (yes/no): ")
if ready.lower() != 'yes':
print("Come back when you're ready! Goodbye.")
sys.exit()
q1 = question_with_response("1. How many players are on the field for one team in American football? (a) 11 (b) 9 (c) 15: ")
if q1.lower() == "a":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is (a) 11.")
q2 = question_with_response("2. In basketball, how many points is a shot from beyond the three-point line worth? (a) 2 (b) 3 (c) 4: ")
if q2.lower() == "b":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is (b) 3.")
q3 = question_with_response("3. What is the maximum duration of a standard professional soccer match (without extra time)? (a) 60 minutes (b) 90 minutes (c) 120 minutes: ")
if q3.lower() == "b":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is (b) 90 minutes.")
q4 = question_with_response("4. In tennis, what is the term used when the score is 40-40? (a) Deuce (b) Match point (c) Advantage: ")
if q4.lower() == "a":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is (a) Deuce.")
q5 = question_with_response("5. In which year did the first modern Olympic Games take place? (a) 1896 (b) 1900 (c) 1912: ")
if q5.lower() == "a":
print("Correct!")
correct += 1
else:
print("Incorrect. The correct answer is (a) 1896.")
print(f'{user_name}, you scored {correct}/{questions}!')
print("\nHomework Hack: Let's try a simple comparison program!")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
if num1 == num2:
print("Both numbers are equal.")
elif num1 > num2:
print(f"The first number ({num1}) is larger.")
else:
print(f"The second number ({num2}) is larger.")
Hello, ! You are running Python using /Users/Priya/nighthawk/Akshaj_2025/venv/bin/python.
Come back when you're ready! Goodbye.
An exception has occurred, use %tb to see the full traceback.
SystemExit
/Users/Priya/nighthawk/Akshaj_2025/venv/lib/python3.12/site-packages/IPython/core/interactiveshell.py:3585: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
Homework 3.7
age = int(input("Enter your age: "))
has_ball = input("Do you have a ball? (yes/no): ").lower()
can_join_game = age >= 8 and has_ball == "yes"
if can_join_game:
if age < 10:
message = "You can only play with the younger kids."
else:
message = "You are allowed to play with the older kids."
print(f"Sounds good! {message}")
else:
print("Youn't can't play without the ball")
Sounds good! You can play only play with the younger kids.