Welcome! I'm Likhith Gowda, a CSE student at SKIT Bangalore.
This repo contains my daily Python exercises as I learn programming.
Problem statement + code
- Write a Python program that asks the user to enter their age and whether they have a driving license (type "yes" or "no"). Using comparison operators (==, !=, >, <, >=, <=) and logical operators (and, or, not), check and display whether the person is 18 years or older, whether they have a license, whether they are eligible to drive (age greater than or equal to 18 and license is "yes"), and whether they are not eligible to drive. Print each result as either True or False.
age = int(input("Enter your age: "))
license_status = input('Do you have a driving license? (yes/no): ')
is_adult = age >= 18
has_license = license_status.lower() == "yes"
eligible_to_drive = is_adult and has_license
not_eligible = not eligible_to_drive
print("\nAge >= 18:", is_adult)
print("Has license:", has_license)
print("Eligible to drive:", eligible_to_drive)
print("Not eligible to drive:", not_eligible)
# Example Outputs:
# Enter your age: 20
# Do you have a driving license? (yes/no): yes
# Age >= 18: True
# Has license: True
# Eligible to drive: True
# Not eligible to drive: False
# Enter your age: 16
# Do you have a driving license? (yes/no): no
# Age >= 18: False
# Has license: False
# Eligible to drive: False
# Not eligible to drive: True
- Ask the user for a number.Using and, check if the number is even AND positive.Print True or False.
# Ask the user for a number
num = int(input("Enter a number: "))
# Check if the number is even AND positive
result = (num % 2 == 0) and (num > 0)
# Print True or False
print(result)
#output
# Example Outputs:
# Enter a number: 6
# True
# Enter a number: -4
# False
# Enter a number: 7
# False
# Enter a number: -3
# False
- Ask the user to enter a day of the week (like "Saturday", "Sunday"). Using or, print True if it is a weekend or holiday, otherwise False.
day = input("Enter a day: ")
is_weekend = (day == "Saturday") or (day == "Sunday")
print("Weekend or holiday:", is_weekend)
#output
Enter a day: Sunday
Weekend or holiday: True
- A store gives a discount based on multiple conditions: You get a 20% discount if your purchase > 5000 and you are a premium member. You get a 10% discount if your purchase > 5000 or you are a loyalty member, but not both conditions. Otherwise, no discount. Task: Write a program to calculate discount percentage for any user input.
# Taking user inputs
your_purchase = float(input("Enter your purchase value: "))
type_of_member = input("Are you a premium member? (yes/no): ").lower()
loyalty_member = input("Are you a loyalty member? (yes/no): ").lower()
# Defining discount messages
discount_20 = "You will get 20% discount"
discount_10 = "You will get 10% discount"
no_discount = "No discount"
# Applying the discount rules
if your_purchase > 5000 and type_of_member == "yes":
print(discount_20)
elif (your_purchase > 5000 or loyalty_member == "yes") and not (your_purchase > 5000 and type_of_member == "yes"):
print(discount_10)
else:
print(no_discount)
#outputs example
Enter your purchase value: 6000
Are you a premium member? (yes/no): yes
Are you a loyalty member? (yes/no): no
You will get 20% discount- Write a Python program for a smart home system that decides whether to turn on the AC, Heater, or keep the room comfortable, based on the following rules: Turn on AC if temperature ≥ 30 or humidity ≥ 70. Turn on Heater if temperature ≤ 15 and humidity ≤ 40. Otherwise, print “Room is comfortable”.
# Take user inputs
temperature = float(input("Enter the temperature (°C): "))
humidity = float(input("Enter the humidity (%): "))
# Apply smart home rules
if temperature >= 30 or humidity >= 70:
print("Turn on AC")
elif temperature <= 15 and humidity <= 40:
print("Turn on Heater")
else:
print("Room is comfortable")
#sample outputs
Enter the temperature (°C): 32
Enter the humidity (%): 50
Turn on AC