Computer Science, asked by ibrahim12376, 2 months ago

Explain the use of if, elif, and else keywords in conditional statements with one example.​

Answers

Answered by allysia
1

Answer:

Take the following code for example:

______________________________

a=int(input("Enter a number from  1 to 10: "))

if a>0 and a<5:

      print ("You think the answer was not good enough.")

elif a>=5 and a<8:

      print ("You think it was okay.")

else:

      print("You think it was nice enough?")

_______________________________

Explanation:

"a" takes user input and the program searches through the condition whether any of them( any as in if and elif) is satisfied by the input, and if no, else is run.

So if n=2,

You think the answer was not good enough. will be the output.

if n=7,

You think it was okay. will be the output.

if n=9, none of the conditions of if and elif is satisfied so else is run,

You think it was nice enough? will be printed.

Similar questions