#3 Python Series..
Saravanan B
Posted on March 8, 2022
Control Flow:
IF - Else :
If a person wants ride a roller coaster the height must be 120cm.
if we want computer to check the height then we have to write a logic in a language which computer understand.
Here is an example:
if(height>120)
print("Can ride")
else
print("Can't ride")
Comparison Operators
">" Greater than
"<" Less then
">=" Greater than or equal to
"<=" Less than or equal to
Nested If Statement:
wanted to check another condition that visitor age is above 18 then ticket price 12$ or less than 18 and greater then 12 ticket price 7$. less than 12 then 5$ per ticket.
If condition:
if another condition:
do this
else:
do this
else:
do this
if year%4 == 0:
if year%100 == 0:
if year%400 == 0:
print("Not Leap year.")
else:
print("Leap year")
else:
print("Leap year")
else:
print("Not leap year.")
Logical operator..
And
Or
Not
π¨ Don't change the code below π
print("Welcome to the Love Calculator!")
name1 = input("What is your name? \n")
name2 = input("What is their name? \n")
π¨ Don't change the code above π
Write your code below this line π
combined_string = name1+name2
lower_case_string = combined_string.lower()
print(lower_case_string)
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
print(true)
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}.")
Posted on March 8, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.