Cool Python Projects
By Abhinav Gupta
Dev.to - https://dev.to/abhidevelopssuntech
SunTech Website - https://suntechdesign.wixsite.com/suntech
Birthday Estimator:
import datetime
def get_birthday_from_user():
year = int(input('What year were you born? '))
month = int(input('What month were you born? '))
day = int(input('What day were you born? '))
user_bday=datetime.date(year,month,day)
return user_bday
def compute_days_between_dates(bday2,today2):
bday2 = datetime.date(today2.year,bday2.month, bday2.day)
days3 = bday2 - today2
print(days3, type(days3))
return days3.days
def print_birthday_information(bday4):
if bday4 < 0:
print('Your Birthday was {0} days ago!'.format(-bday4))
def main ():
user_bday2 = get_birthday_from_user()
today = datetime.date.today()
days_to_bday = compute_days_between_dates(user_bday2,today)
print_birthday_information(days_to_bday)
main()
Guess that Number Game:
import random
print("I have thought of a number between 1 and 10. But I will not tell you, you have to guess it.")
the_number = random.randint(1, 10)
username = input("What is your name? ")
if username == 'Abhinav Gupta':
print("Hello Abhinav Gupta, my name is Alexa.")
user_int = -1
while user_int != the_number:
user_input = input("Guess a number between 1 and 10. ")
user_int = int(user_input)
if user_int > the_number:
print('Oh No {0}, Your guess {1} is too high!'.format(username, user_int))
elif user_int < the_number:
print('Uh Oh, {0} Your guess {1} is to small!'.format(username, user_int))
else:
print("YOU GOT IT, WELL DONE!")
print("Well Done, take rest now.")
Next Leap Year Project:
print("In this app you will know when the next leap year is this year a leap year.")
what_is_leap_year = input("Do you know what a leap year is? a)YES or b)NO? ")
if what_is_leap_year == 'a':
print("Awesome!")
elif what_is_leap_year == 'b':
print("I will tell you.")
print("A leap year happens every 4 years when February has 29 days, understand.")
print()
print("Next I will tell you if it is a leap year now.")
what_year = int(input("What year is it? "))
division = (float(what_year/4))
if division.is_integer():
print('The year {} is a leap year'.format(what_year))
else:
print("It is not a leap year.")
division_int = int(division)
for x in range(2):
next_division = division_int + 1
next_leap_year = next_division * 4
print('The next leap year will happen in {}'.format(next_leap_year))
division_int = division_int + 1
print("I hope you liked this calendar game!")
Calculator Project:
def divide (user_number_3, user_number_4):
result1 = user_number_3 / user_number_4
return result1
def add (user_number_3, user_number_4):
result2 = user_number_3 + user_number_4
return result2
def multiply (user_number_3, user_number_4):
result3 = user_number_3 * user_number_4
return result3
def subtraction (user_number_3, user_number_4):
result4 = user_number_3 - user_number_4
return result4
def main ():
user_choice = input("Do you want to a)add or b)multiply c)divide d) subtract - Enter a, b , c, or d ")
user_number_1 = int(input('Enter first number '))
user_number_2 = int(input('Enter second number '))
if user_choice == 'a':
result = add(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'b':
result = multiply(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'c':
result = divide(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
if user_choice == 'd':
result = subtraction(user_number_1, user_number_2)
print('The result is: {}'.format(result))
print("Hope you had fun with our calculator!")
main()
Car Shopping Project:
print('@*@*@*@*@*@*@*@*@*@*@*@*@*@*')
print('CAR TIME')
print('Welcome Shopper - Lets take you on a car shopping journey!!!')
print()
print('Zoooooooooooooooooooooommmmmmmmmmm!')
print('@*@*@*@*@*@*@*@*@*@*@*@*@*@*')
print('')
user_car = input('Do you want a) sports car, b) a luxury car,or a c) normal car d) Nothing? Enter a,b,c,or d - ')
#just giving value to variables to start with
user_like = 'az'
if user_car == 'd':
print('Bye Bye!')
exit()
#code for sports car
if user_car == 'a':
print('Welcome Sports Car shopper')
user_money= input('How much money do you want to spend (in million dollars?)')
user_money_int = int(user_money)
user_model = input('Choose from these cars - a) Bugatti Chiron; b) Lamborghini Huracan c) Bugatti Divo,Choose a,b or c - ')
if user_model== 'a':
number_of_cars = (user_money_int)/3
car_name = 'Bugatti Chiron'
elif user_model == 'b':
number_of_cars = (user_money_int)/0.5
car_name = 'Lamborghini Huracan'
elif user_model == 'c' :
number_of_cars = (user_money_int)/6
car_name = 'Bugatti Divo'
print('***** You can buy {0} {1} '.format(number_of_cars,car_name))
#Chiron = 3M, Huracan = 0.3M, Divo = 6M
print()
#code for luxury car
if user_car == 'b':
print('Welcome Luxury Car shopper')
user_money2=input('How much money do you want to spend(in millions?) ')
user_money2_int = int(user_money2)
user_model2 = input('Choose from these cars - a) Rolls Royce; b) Audi c) BMW, choose a,b,or c - ')
if user_model2 == 'a' or 'Rolls Royce':
number_of_cars2 = (user_money2_int)/1
car_name= 'Rolls Royce'
elif user_model2 =='b' or 'Audi':
number_of_cars2 = (user_money2_int)/0.1
car_name = 'Audi'
elif user_model2 =='c' or 'BMW':
number_of_cars2 = (user_money2_int)/0.2
car_name = 'BMW'
print('***** You can buy {0} {1} cars'.format(number_of_cars2,car_name))
#Royce = 1M, Audi = 0.1M , BMW = 0.2M
print()
#code for normal car
if user_car == 'c':
print('Welcome Normal Car shopper')
user_money3= input('How much money do you want to spend(in thousand dollars)?')
user_money3_int = int(user_money3)
user_model3 = input('Choose from these cars - a) Toyota Corolla; b) Nissan Altima c) Honda Accord, choose a,b,or c - ')
if user_model3 == 'a' :
number_of_cars3 = (user_money3_int)/19.6
car_name = 'Toyota Corolla'
elif user_model3 == 'b' :
number_of_cars3 = (user_money3_int)/21.1
car_name = 'Nissan Altima'
elif user_model3 == 'c' :
number_of_cars3 = (user_money3_int)/20
car_name = 'Honda Accord'
print('***** You can buy {0} {1} cars'.format(number_of_cars3,car_name))
#Toyota = 19.6K, Nissan = 21.1K, Honda = 20K
print('***** Hope you enjoyed shopping with us *****')
print()
if user_car !='d':
user_like = input('How did you like the experience of shopping a car? a) GOOD OR b) BAD? ')
if user_like == 'a':
print('Thanks! We are sooooooooo happy to see you happy!')
else: print('I will someday make you feel that you like this Car Shopper!')