Python Day 3 - Bermain Dengan Logika (if, elif dan else)

Tema yang saya pelajari di hari ketiga ini adalah Bermain dengan logika (if, elif dan else). Tema yang cukup menarik dan penuh tantangan, apalagi sudah hampir 1 dekade saya gak pernah nyentuh lagi yang namanya programming, sehingga cukup menghangatkan kembali otak saya yang sudah lama dingin hehehe
Ada beberapa program yang saya buat tadi malam, antara lain :
Genap atau Ganjil (Operator Modulo %)
number = int(input("Which number do you want to check? "))
hitung = number % 2
if hitung == 0:
print("This is an even number.")
else:
print("This is and odd number.")
BMI - Body Mass Index (Nyindir yang lagi Gagal Diet)
height = float(input("enter your height in m: "))
weight = float(input("enter your weight in kg: "))
bmi = weight / height ** 2
bmi_bulat = round(bmi)
if bmi < 18.5:
print(f"{weight} / ({height} x {height}) = {bmi}")
print(f"Your BMI is {bmi_bulat}. You are underweight.")
elif bmi < 25:
print(f"{weight} / ({height} x {height}) = {bmi}")
print(f"Your BMI is {bmi_bulat}. You are normal weight.")
elif bmi < 30:
print(f"{weight} / ({height} x {height}) = {bmi}")
print(f"Your BMI is {bmi_bulat}. You are slightly overweight.")
elif bmi < 35:
print(f"{weight} / ({height} x {height}) = {bmi}")
print(f"Your BMI is {bmi_bulat}. You are obese.")
else:
print(f"{weight} / ({height} x {height}) = {bmi}")
print(f"Your BMI is {bmi_bulat}. You are clinically obese.")
Tahun Kabisat (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.")
Jualan Pizza
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or 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
print(f"\nYou Choose Small Pizza: ${bill}")
elif size == "M":
bill += 20
print(f"\nYou Choose Medium Pizza: ${bill}")
else:
bill += 25
print(f"\nYou Choose Large Pizza: ${bill}")
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}")
Kalkulator Cinta Sejati (True Love Calculator)
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
name_gabung = name1 + " " + name2
name_lo = name_gabung.lower()
t = name_lo.count('t')
r = name_lo.count('r')
u = name_lo.count('u')
e = name_lo.count('e')
true = str(t + r + u + e)
l = name_lo.count('l')
o = name_lo.count('o')
v = name_lo.count('v')
e = name_lo.count('e')
love = str(l + o + v + e)
true_love = int(true + love)
if true_love < 10 or true_love > 90:
print(f"Your score is {true_love}, you go together like coke and mentos.")
elif true_love >= 40 and true_love <= 50:
print(f"Your score is {true_love}, you are alright together.")
else:
print(f"Your score is {true_love}.")
Asik sekali, saking semangatnya dan semalam akhirnya tidur di kisaran jam 00.00 lagi, mudah-mudahan selalu diberikan kesehatan dan kemudahan dalam setiap aktivitas... Amiiin.




