Learn Python-100 Days Of Code with Khemlall DAY 3-Control flow, code blocks scope and logical Operator

print(“Welcome to the rollercoaster!”)
height = int(input(“What is your height in cm? “))
if height<120:

Python Greater Than (>) Operator

Less Than or Equal To (<=) Operator

Equal To or Greater Than — Python (>=) Operator

Python Not Equal Operator (!=) Operator

Python Equal To (==) Operator

Figure out if a number is Odd or Even

Instructions

6 % 2 = 0
5 % 2 = 1
14 % 4 = 2

Example Input 1

43

Example Output 1

This is an odd number.

Example Input 2

94

Example Output 2

This is an even number.
elif python
nest if else python

BMI Calculator 2.0

Instructions

  • Under 18.5 they are underweight
  • Over 18.5 but below 25 they have a normal weight
  • Over 25 but below 30 they are slightly overweight
  • Over 30 but below 35 they are obese
  • Above 35 they are clinically obese.

Example Input

weight = 85height = 1.75

Example Output

Your BMI is 28, you are slightly overweight.
"Your BMI is 18, you are underweight.""Your BMI is 22, you have a normal weight.""Your BMI is 28, you are slightly overweight.""Your BMI is 33, you are obese.""Your BMI is 40, you are clinically obese."
  1. Try to use the exponent operator in your code.
  2. Remember to round your result to the nearest whole number.
  3. Make sure you include the words in bold from the interpretations.

Test Your Code

Leap Year

💪This is a Difficult Challenge 💪

Instructions

Example Input 1

2400

Example Output 1

Leap year.

Example Input 2

1989

Example Output 2

Not leap year.

Hint

  1. Try to visualize the rules by creating a flow chart on www.draw.io
  2. If you really get stuck, you can see the flow chart I created:
# 🚨 Don't change the code below 👇year = int(input("Which year do you want to check? "))# 🚨 Don't change the code above 👆#Write your code below this line 👇#without function# is it clearly divisible by 4?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")

Let enhance this……but in future lesson we will use function to do this. but let me just give you another way of doing this…

# 🚨 Don't change the code below 👇year = int(input("Which year do you want to check? "))# 🚨 Don't change the code above 👆# Default function to implement conditions to check leap yeardef CheckLeap(Year):# Checking if the given year is leap yearif((Year % 400 == 0) or(Year % 100 != 0) and(Year % 4 == 0)):print(“leap Year”);# Else it is not a leap yearelse:print (“Not leap Year using function”)# Printing resultCheckLeap(year)

CODE CHALLENGE- BurgerOrder

Instructions

Small Burger: $15Medium Burger: $20Large Burger: $25Pepperoni for Small Burger: +$2Pepperoni for Medium or Large Burger: +$3Extra cheese for any size Burger: + $1

Example Input

size = "L"add_pepperoni = "Y"extra_cheese = "N"

Example Output

Your final bill is: $28.

Hint

  1. Think about what you’ve learnt about multiple if statements and see if you can reduce the number of lines of code while having the same functionality.

Test Your Code

https://www.geeksforgeeks.org/python-logical-operators-with-examples-improvement-needed/

Logical AND operator

Love Calculator

💪 This is a Difficult Challenge 💪

Instructions

Example Input 1

name1 = "Kanye West"name2 = "Kim Kardashian"

Example Output 1

Your score is 42, you are alright together.

Example Input 2

name1 = "Brad Pitt"name2 = "Jennifer Aniston"

Example Output 2

Your score is 73.
"Your score is 47, you are alright together.""Your score is 125, you go together like coke and mentos.""Your score is 54."

Hint

  1. The lower() function changes all the letters in a string to lower case.
  1. The count() function will give you the number of times a letter occurs in a string.

Test Your Code

# 🚨 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 👇combinedName = name1+name2lowercasestring = combinedName.lower()t= lowercasestring.count('t')r =lowercasestring.count('r')u= lowercasestring.count('u')e= lowercasestring.count('e')true = t+r+u+el=lowercasestring.count('l')o=lowercasestring.count('o')v=lowercasestring.count('v')e=lowercasestring.count('e')love = l+o+v+elove_score = str(true) + str(love)int_score = int(true) + int(love)print(love_score)if (int_score <10) or (int_score>90):print(f"Your score is {love_score}, you go together like coke and mentos")elif int_score<=40 and int_score<=50:print(f"Your score is {love_score}, you are alright together.")else:print(f"Your score is {love_score}.")

My replit:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Khemlall Mangal

Khemlall Mangal

31 Followers

I am a passionate coder, QA Engineer, and someone who enjoys the outdoors.