DEV Community

Saravanan B
Saravanan B

Posted on

#3 Python Series..

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

Image description

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

Image description

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

Top comments (0)