Day 3 - Control Flow & Logical Operator


Posted by pei_______ on 2022-04-13

learning from 100 Days of Code: The Complete Python Pro Bootcamp for 2022


if condition1:
do A
elif condition2:
do B
else:
do C

if condition1:
do A
if condition2:
do B
if condition3:
do C

if condition_combine:
do A
(condition_combine = A and B / C or D / not E)


# Odd or Even

number = int(input("Which number do you want to check? "))

if number % 2 == 0:
    print("This is an even number.")
else:
    print("This is an odd number.")

# 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 underweight.")
elif bmi <= 25:
    print(f"Your BMI is {bmi}, you have a normal weight.")
elif bmi <= 30:
    print(f"Your BMI is {bmi}, you are slightly overweight.")
elif bmi <= 35:
    print(f"Your BMI is {bmi}, you are obese.")
else:
    print(f"Your BMI is {bmi}, you are clinically obese.")
# Leap year or not

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.")

# Love Calculator

print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")

total_name = name1.lower() + name2.lower()
true = total_name.count('t')+total_name.count('r')+total_name.count('u')+total_name.count('e')
love = total_name.count('l')+total_name.count('o')+total_name.count('v')+total_name.count('e')

score = true * 10 + love

if score >= 90 or score <= 10 :
    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}.")

#Python #課堂筆記 #100 Days of Code







Related Posts

簡明 SQL 資料庫語法入門教學

簡明 SQL 資料庫語法入門教學

[02] Functional Component

[02] Functional Component

JS 模組化:Import 和 export

JS 模組化:Import 和 export


Comments