Python- Day3

Nidhi Ashtikar
7 min readJul 13, 2024

--

Conditions:

  1. If Else :

Project 1: Welcome to the rollercoaster ride!

#if -else

print("Welcome to the rollercoaster ride!\n")

height = int(input("What is your height in cm?\n"))

if height > 120:
print("----------You can ride the rollercoaster!------------")
else:
print("********* Sorry, you have to grow taller before you can ride!*********")

>>

Welcome to rollercoster ride!

What is your height in cm?
50
********* Sorry, you have to grow taller before you can ride!*********

''

Welcome to rollercoster ride!

What is your height in cm?
150
----------You can ride the rollercoaster!------------

Project 2: ODD or EVEN

#ODD OR EVEN

num = int(input("Which number do you want to check \n"))

if num % 2 == 0:
print("-------This number is EVEN----------")
else:
print("--------This is ODD number-----------")



>>

Which number do you want to check
2536621166
This number is EVEN


''

Which number do you want to check
52145567
This is ODD number

2. Nested If-else

print("------------Welcome to rollercoster ride!------------\n")

height = int(input("What is your height in cm?\n"))

if height > 120:
print("----------You can ride the rollercoaster!------------")
age = int(input("What is your age?\n"))

if age <= 18:
print("You have to pay $7.00")

else:
print("You have pay $18.00")

else:
print("********* Sorry, you have to grow taller before you can ride!*********")


>>

------------Welcome to rollercoster ride!------------

What is your height in cm?
130
----------You can ride the rollercoaster!------------
What is your age?
20
You have pay $18.00

3. Elif statement:



print("------------Welcome to rollercoster ride!---------------\n")
height = int(input("What is your height in cm?\n"))

if height > 120:
print("----------You can ride the rollercoaster!------------")
age = int(input("What is your age?\n"))

if age < 12:
print("You have to pay $5.00")
elif age <= 18:
print("You have to pay $7.00")
else:
print("You have pay $12.00")

else:
print("********* Sorry, you have to grow taller before you can ride!*********")




>>

------------Welcome to rollercoster ride!---------------

What is your height in cm?
130
----------You can ride the rollercoaster!------------
What is your age?
14
You have to pay $7.00

Project 2: BIM 2.0

height = float(input("What is your height?"))
weight = int(input("What is your weight?"))

bmi = weight / height

if bmi < 18.5:
print(f"Your Body Mass Index is {bmi} and you are underweight")
if bmi < 25:
print(f"Your Body Mass Index is {bmi} and you have normal weight")
elif bmi < 30:
print(f"Your Body Mass Index is {bmi} and you are slightly overweight")
elif bmi < 35:
print(f"Your Body Mass Index is {bmi} and you are obese")

else:
print(f"Your Body Mass Index is {bmi} and you are clinically obese")

>>

What is your height?1.52
What is your weight?85
Your Body Mass Index is 55.921052631578945 and you are clinically obese

Project 3: Check Leap Year

year = int(input("Which year you want to check if its leap year or not.\n"))

if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("This is a leap year")
else:
print("This is not a leap year")
else:
print("This is leap year")

else:
print("This is not a leap year")

>>

Which year you want to check if its leap year or not.
2025
This is not a leap year

''

Which year you want to check if its leap year or not.
2024
This is leap year

Project 4: #Rollercoster ride with photo

print("------------Welcome to rollercoster ride!---------------\n")
height = int(input("What is your height in cm?\n"))
bill = 0

if height > 120:
print("----------You can ride the rollercoaster!------------")
age = int(input("What is your age?\n"))

if age < 12:
bill = 5
print("Child ticket are for $5.00")
elif age <= 18:
bill = 7
print("Youth ticket are for $7.00")
else:
bill = 12
print("Adult ticket are for $12.00")

photo = input("Do you want photo? Y or N. \n")

if photo == "Y":
bill += 3

print(f"Your Bill is ${bill}")


else:
print("********* Sorry, you have to grow taller before you can ride!*********")



>>

------------Welcome to rollercoster ride!---------------

What is your height in cm?
150
----------You can ride the rollercoaster!------------
What is your age?
25
Adult ticket are for $12.00
Do you want photo? Y or N.
Y
Your Bill is 15

''


------------Welcome to rollercoster ride!---------------

What is your height in cm?
150
----------You can ride the rollercoaster!------------
What is your age?
25
Adult ticket are for $12.00
Do you want photo? Y or N.
N
Your Bill is $12
PS C:\Users\Hp\Desktop\Python>

Project 5: #PIZZA ORDER


print(" ------ Thanks for choosing Python Pizza'S --------\n\n")

print("Check our Prices:\n")
print("Small for $15, Medium for $20 and Large for $25.\n")
print("Extra pepperoni for small - $2, for Medium and Large - $3.\n")
print("Extra Cheese for $1.\n")



size= input("What size do you want- S, M, or L\n")
add_pep = input ("Do you want to add pepperoni- Y or N\n")
extra_cheese = input("Do you want to add cheese- Y or N\n")



bill = 0

if size == "S":
bill += 15

elif size == "M":
bill += 20

else:
bill += 25


if add_pep == "Y":
if size == "S":
bill += 2
else:
bill += 3


if extra_cheese == "Y":
bill += 1


print(f"You final bill is {bill}.")


>>

------ Thanks for choosing Python Pizza'S --------


Check our Prices:

Small for $15, Medium for $20 and Large for $25.

Extra pepperoni for small - $2, for Medium and Large - $3.

Extra Cheese for $1.

What size do you want- S, M, or L
L
Do you want to add pepperoni- Y or N
Y
Do you want to add cheese- Y or N
N
You final bill is 28.

Logical Operator

Logical Operator using prior project

Project 6: Welcome to the rollercoaster ride!

print("------------Welcome to rollercoster ride!---------------\n")
height = int(input("What is your height in cm?\n"))
bill = 0

if height > 120:
print("----------You can ride the rollercoaster!------------")
age = int(input("What is your age?\n"))

if age < 12:
bill = 5
print("Child ticket are for $5.00")
elif age <= 18:
bill = 7
print("Youth ticket are for $7.00")
elif age >= 45 and age <= 55:
print("Free Tickets! ")
else:
bill = 12
print("Adult ticket are for $12.00")

photo = input("Do you want photo? Y or N. \n")

if photo == "Y":
bill += 3

print(f"Your Bill is ${bill}")


else:
print("********* Sorry, you have to grow taller before you can ride!*********")

>>

------------Welcome to rollercoster ride!---------------

What is your height in cm?
150
----------You can ride the rollercoaster!------------
What is your age?
45
Free Tickets!
Do you want photo? Y or N.
Y
Your Bill is $3

Project 7: Love Calculator

Here we will learn
1. Converting into lower case
2. count

lower_name =  combined_name.lower()
t =  lower_name.count("t")
print("-------Welcome to Love Calculator-------\n")

name1 = input("What is your name?\n")
name2 = input("What is their name?\n")

combined_name = name1 + name2
lower_name = combined_name.lower()


t = lower_name.count("t")
r = lower_name.count("r")
u = lower_name.count("u")
e = lower_name.count("e")
first_digt = t+r+u+e

l = lower_name.count("l")
o = lower_name.count("o")
v = lower_name.count("v")
e = lower_name.count("e")
second_digt = l+o+v+e

score = int(str(first_digt) + str(second_digt))

if (score < 10) and (score > 90):
print(f"Your Score is {score}, you go together like coke and mentos.")

elif (score >= 40) and (score <= 50):
print(f"Your Score is {score}, you are alright together")

else:
print(f"Your Score is {score}")



>>
-------Welcome to Love Calculator-------

What is your name?
Keeny laas
What is their name?
Meen
Your Score is 45, you are alright together

Project 8: Welcome to Treasure Island

print('''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")

choice1 = input('Go want to go Left or Right?\n').lower()

if choice1 == "left":
choice2 = input('Want to Wait or swim?\n').lower()

if choice2 == "wait":
choice3 = input('Choose door- red/blue/yellow\n').lower()

if choice3 == "red":
print("Fire Room, Game Over!")
elif choice3 == "blue":
print("Wate Room, Game Over!")
elif choice3 == "yellow":
print("YOU WON")
else:
print("Wrong Room, Game Over!")

else:
print("Learn patience, Game Over!")

else:
print("Always choose right direction, Game over!")

>>

Welcome to Treasure Island.
Your mission is to find the treasure.
Go want to go Left or Right?
left
Want to Wait or swim?
wait
Choose door- red/blue/yellow
yellow
YOU WON

''

Welcome to Treasure Island.
Your mission is to find the treasure.
Go want to go Left or Right?
left
Want to Wait or swim?
wait
Choose door- red/blue/yellow
red
Fire Room, Game Over!

If you found this guide helpful then do click on 👏 the button.

Follow for more Learning like this 😊

If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!

Thanks for spending your valuable time learning to enhance your knowledge!

--

--

Nidhi Ashtikar
Nidhi Ashtikar

Written by Nidhi Ashtikar

Experienced AWS DevOps professional with a passion for writing insightful articles.

No responses yet