#Comparison Operators
''' Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<=
== Equal to
!= Not equalto
'''
#3.1 Odd or Even
number = int(input("Which number do you want to check?"))
if number%2 ==0:
print("This is a even number.")
else:
print("This is an odd number.")
#modulo %
#Nested if/else
#if/elif/else
height=int(input("What is your height?"))
if height >= 120:
print("You can ride the rollercoaster!")
age = int(input("What is your age?"))
if age<12:
print("Please pay $5.")
elif age<=18:
print("Please pay $7.")
else:
print("Please pay $12.")
else:
print("Sorry,you have to grow taller before you can ride.")
#3.2 BMI 2.0
height = float(input("enter your height in m:"))
weight = float(input("enter your weight in kg:"))
bmi=round(weight/height**2)
if bmi <18.5:
print(f"Your BMI is {bmi},you are under wieght.")
elif bmi < 25:
print(f"Your BMI is {bmi},you are normal wieght.")
elif bmi < 30:
print(f"Your BMI is {bmi},you are overweight.")
elif bmi < 35:
print(f"Your BMI is {bmi},you are under obese.")
else:
print(f"Your BMI is {bmi},you are clinically obese.")
#3.3 Leap Year
year = int(input("Which year do you want to check?"))
if year % 4==0:
if year%100==0:
if year%400==0:
print("Leap Year")
else:
print("Not Leap Year")
else:
print("Leap Year")
else:
print("Not Leap Year")
#Multiple if
height=int(input("What is your height?"))
if height >120:
print("You can ride the rollercoaster!")
age = int(input("What is your age?"))
if age < 12:
bill = 5
print("Child tickets are $5.")
elif age <= 18:
bill = 7
print("Youth ticktets are $7.")
elif age > 18 :
bill = 12
print("Adult tickets are $12.")
wants_photo = input("Do you want a photo taken ? Y or N.")
if wants_photo == 'Y':
bill+=3
print(f"Your final bill is ${bill}")
else:
print("Sorry,you have to grow taller before you can ride.")
#3.4 Pizza Order
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want?S,M,oe L")
add_pepperoni = input("Do you want pepperoni?Y or N")
extra_cheese = input("Do you want extra cheese? Y or N ")
bill =0
if size == 'S':
bill += 15
elif size =='M':
bill += 20
elif size =='L':
bill += 25
if add_pepperoni == 'Y':
if size == 'S':
bill+=2
else:
bill+=3
if extra_cheese ==' Y':
bill+=1
print(f"Your final bill is :${bill}")
# Logical Operator
#A and B A or B Not A
bill =0
height=int(input("What is your height?"))
if height >120:
print("You can ride the rollercoaster!")
age = int(input("What is your age?"))
if age < 12:
bill = 5
print("Child tickets are $5.")
elif age <= 18:
bill = 7
print("Youth ticktets are $7.")
elif age>=45 and age<=55:
print("Everything is going to be ok.Have a free ride on us!")
else:
bill = 12
print("Adult tickets are $12.")
wants_photo = input("Do you want a photo taken ? Y or N.")
if wants_photo == 'Y':
bill+=3
print(f"Your final bill is ${bill}")
else:
print("Sorry,you have to grow taller before you can ride.")
#3.5 Love Calculator
print("Welcome to the Love Calculator!")
name1 = input("What is your name?\n")
name2 = input("What is your name?\n")
combined_string_name = name1 + name2
lower_case_string = combined_string_name.lower()
t = lower_case_string.count("t")
r = lower_case_string.count("r")
u = lower_case_string.count("u")
e = lower_case_string.count("e")
true = t + r + u + e
l = lower_case_string.count("l")
o = lower_case_string.count("o")
v = lower_case_string.count("v")
e = lower_case_string.count("e")
love = l + o + v + e
love_score = int(str(true) +str(love))
if (love_score <10) or (love_score >90):
print(f"Your score is {love_score},you go together like coke and mentos.")
elif (love_score >= 40) and (love_score <= 50):
print(f"Your score is {love_score},you are alright together.")
else:
print(f"Your score is {love_score}")
#Treasure Island
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
#escape the string:\
choice1 = input('You\'re at a crossroad,where do you want to go? Type "left" or "right".\n').lower()
if choice1 == "left":
choice2 = input('You\'ve come to a lake.There is an island in the middle of the lake.Type "wait" to wait for a boat.Type "swim" to swim across.\n').lower()
if choice2 == "wait":
choice3 = input('You arrive at the island unharmed.There is a house with 3 doors.One red,one yellow and one blue.Which color do you choose?\n').lower()
if choice3 == "red":
print("It is a room full of fire.Game Over.")
elif choice3 == "yellow":
print("You found the treasure!You win!")
elif choice3 == "blue":
print("You enter a room of beasts.Game Over.")
else:
print("You choose a door that doesn't exist.Game Over.")
else:
print("You got attacked by an angry trout.Game Over.")
else:
print("You fell into a hole.Game Over.")
Day3_Udemy Python 100days
最新推荐文章于 2024-08-19 14:41:29 发布