Wednesday, February 28, 2024

 

Nesting in if statement

Nesting is where we put an if statement within an if statement using the power of indenting. The second if statement within the first if statement must be indented and its print statement needs to be indented one more time.

Here is code using Nesting :- 

tvShow = input("What is your favorite tv show? ")
if tvShow == "peppa pig":
  print("Ugh, why?")
  faveCharacter = input("Who is your favorite character? ")
  if faveCharacter == "daddy pig":
    print("Right answer")
  else:
    print("Nah, Daddy Pig's the greatest")
elif tvShow == "paw patrol":
  print("Aww, sad times")
else:
  print("Yeah, that's cool and all…") 



Today's focus is using all the skills you have learned so far:
  • input and output
  • concatenation
  • if statements
  • nested if statements

print("Wholesome Positivity machine")
userName = input("Who are you?:")
if userName == "appu" or userName == "angshu" or userName == "rana":
  print("Good morning",userName)
  userWant= input("What do you want to achieve:")
  print("That is Good to know that You",userWant)
  userRating=input("On a scale of 1-10 how do you feel today:")
  if userRating == "5" or userRating =="6" or userRating =="7" or userRating =="8" or userRating =="9" or userRating =="10":
    print ("It is pretty good today for you")
    print("Hey",userName,"keep your chin up!Today you are going to Teach people to code! in the most amazing way")
  elif userRating == "1" or userRating =="2" or userRating =="3" or userRating =="4" :
    print("Boost yourself to be more energetic .. I know one day you can win the world.")
else:
  print("we dont know you")

No comments:

Post a Comment

  2D Dictionaries Remember that dictionaries are very similar to lists, except that they store data as key:value pairs. The value is what it...