Skip to content

Instantly share code, notes, and snippets.

@princylakhanpal
Created April 20, 2025 18:31
Show Gist options
  • Save princylakhanpal/f5e14ad2494128cac1b7c7c5c631a9c9 to your computer and use it in GitHub Desktop.
Save princylakhanpal/f5e14ad2494128cac1b7c7c5c631a9c9 to your computer and use it in GitHub Desktop.
homework for lesson 4
# Exercise 1: Temperature Classification
# You're developing a weather application. Write a program that takes
# a temperature in Fahrenheit as input. If the temperature is above
# 85°F, print "Hot day ahead!".
temperature = int(input("Enter the temperature in Fahrenheit: "))
if temperature > 85:
print("Hot day ahead!")
# ---------------------------------------------------------------------
# Exercise 2: Grade Classifier
# As a teacher, you want to automate grading. Write a program that
# takes a student's score as input and prints "Pass" if the score is
# 50 or above, otherwise print "Fail".
# Do not forget that the input() function returns a string value and
# you need to convert it so you can use the value as a number.
student_score = int(input("Enter student score:"))
if student_score >= 50:
print("Pass")
else:
print("Fail")
# ---------------------------------------------------------------------
# Exercise 3: Scholarship Eligibility
# Your university offers scholarships based on academic performance.
# Write a program that takes a student's GPA as input. If the GPA
# is greater than or equal to 3.5, print
# "Congratulations, you're eligible for a scholarship!". If it's
# between 3.0 and 3.49, print "You're on the waiting list."
# Otherwise, print "Keep up the good work."
# Do not forget that the input() function returns a string value and
# you need to convert it so you can use the value as a number.
# The function int() converts the number to an integer, and the function
# float() converts the number to a float.
gpa = float(input("Enter your GPA: "))
if gpa >= 3.5:
print("Congratulations, you're eligible for a scholarship!")
elif gpa >= 3.0 <= 3.49:
print("You're on the waiting list.")
else:
print("Keep up the good work.")
# ---------------------------------------------------------------------
# Exercise 4: Shopping Discount
# A store is offering a discount on a product. Write a program that
# takes the original price and the discount percentage as input.
# If the discounted price is less than $50, print "Great deal!".
# Otherwise, print "Might want to wait for a better offer."
original_price = float(input("Enter product original price: "))
discount_percentage = float(input("Enter discount percentage: "))
discounted_price = original_price - (discount_percentage * 100)
if discounted_price < 50:
print("Great deal!")
else:
print("Might want to wait for a better offer.")
# ---------------------------------------------------------------------
# Exercise 5: Movie Night Decision
# You and your friends are deciding on a movie to watch. Write a
# program that takes two movie ratings as input. If both ratings
# are above 7, print "Let's watch both!". Otherwise,
# print "Let's just pick one."
first_movie_rating = int(input("Enter rating for movie 1:"))
second_movie_rating = int(input("Enter rating for movie 2:"))
if first_movie_rating and second_movie_rating > 7:
print("Let's watch both!")
else:
print("Let's just pick one")
# ---------------------------------------------------------------------
# Exercise 6: Restaurant Recommendation
# You're building a restaurant recommendation system. Write a program
# that takes a person's mood (happy or sad) and hunger level
# (high or low) as input. If they're happy and hungry, recommend
# a fancy restaurant. If they're sad and hungry, recommend comfort food.
# For other cases, recommend a casual dining place.
mood = input("Is your mood happy or sad?")
hunger = input("Is your hunger level low or high?")
if mood == "happy" and hunger == "high":
print("You should go to a fancy restaurant!")
elif mood == "sad" and hunger =="high":
print("You should eat comfort food.")
else:
print("Go to a casual dining place.")
# ---------------------------------------------------------------------
# Exercise 7: Exercise 7: Tax Bracket Calculator
# You're building a tax calculation system. Write a program that
# takes a person's annual income as input. Use conditionals
# to determine their tax bracket based on the following rules:
# - If income is less than $40,000, tax rate is 10%.
# - If income is between $40,000 and $100,000 (inclusive), tax rate is 20%.
# - If income is greater than $100,000, tax rate is 30%.
# Remember that a tax rate of 10% can be represented as 10/100 or 0.1
# Print the calculated tax amount for the given income.
annual_income = float(input("Enter your annual income: "))
if annual_income < 40000.0:
tax_amount = annual_income * 0.1
print(f"Your tax amount is ${tax_amount}")
if annual_income >= 40000.0 and annual_income <= 100000.0:
tax_amount = annual_income * 0.2
print(f"Your tax amount is ${tax_amount}")
if annual_income > 100000.0:
tax_amount = annual_income * 0.3
print(f"Your tax amount is ${tax_amount}")
# ---------------------------------------------------------------------
# Exercise 8: Ticket Pricing System
# You're working on a ticket booking system for an amusement park.
# Write a program that takes a person's age as input and determines
# their ticket price based on the following rules:
# - Children (ages 3 to 12): $10
# - Adults (ages 13 to 64): $20
# - Seniors (ages 65 and above): $15
# Print the calculated ticket price for the given age.
age = int(input("Enter your age:"))
if age >= 3 and age <= 12:
print("The ticket price for the child is $10.")
elif age >= 13 and age <= 64:
print("The ticket price for the adult is $20.")
elif age >= 65:
print("The ticket price for the senior is $15.")
# ---------------------------------------------------------------------
# Exercise 9: Password Strength Checker
# Create a program that takes a password as input and checks its
# strength based on the following rules:
# If the password is less than 8 characters, print "Weak password."
# If the password is 8 to 12 characters long, print "Moderate password."
# If the password is more than 12 characters, print "Strong password
# You can use len() function to get the length of a given string.
password = input("Enter your password: ")
length = len(password)
print(length)
if length < 8:
print("Weak password.")
if length > 8 and length < 12:
print("Moderate password.")
if length > 12:
print("Strong password.")
@sunve-careerist
Copy link

Exercise 3: Scholarship Eligibility

Issue: This condition is incorrect:
elif gpa >= 3.0 <= 3.49:

This will always evaluate 3.0 <= 3.49 as True, so it's equivalent to just gpa >= 3.0.

Corrected version:
elif 3.0 <= gpa < 3.5:

Exercise 4: Shopping Discount

Issue: This line is incorrect:
discounted_price = original_price - (discount_percentage * 100)

Multiplying the percentage by 100 doesn’t make sense.

Corrected version:
discounted_price = original_price - (original_price * discount_percentage / 100)

Exercise 5: Movie Night Decision

Issue: This condition is logically flawed:
if first_movie_rating and second_movie_rating > 7:

This checks if second_movie_rating > 7, and first_movie_rating is truthy (non-zero), which isn't the intended comparison.

Corrected version:
if first_movie_rating > 7 and second_movie_rating > 7:

Exercise 9: Password Strength Checker

Issue: This condition misses passwords that are exactly 12 characters:

if length > 8 and length < 12: # Excludes 12

Corrected version:
elif 8 <= length <= 12:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment