If/Elif/Else Statement

In Multimedia, we started to learn about Python. Ever wonder what is a Python? Python is a high-level programming language designed to be easy to read and simple to implement. Now, in Python we have a lot of functions and code. This include the If statement which I will be talking about. You might be wondering, what is If statement? An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Here is an Example:

Viade = 189

Wurple = 389

if Wurple > Viade:

print(“Wurple is the best player”)

What should be the result? The result should be a sentence that is “Wurple is the best player”

Now there also elif statement. An elif is a statement that will continue if statement. How? If the If is wrong then it will run the elif. An Elif statement can be like this:

 

Viade = 189

Wurple = 189

if Wurple < Viade:

print(“Wurple is the best player”)

elif Viade == Wurple:

print(“Viade and Wurple are both equal players”)

But what happen if both statement fail? Well no worries because we got an else statement! An else statement is like a executioner! We use it at the end because if both statement fail us, else is here to save the day! An else statement example can be like this:

Viade = 189

Wurple = 389

if Wurple < Viade:

   print(“Wurple is the best player”)

elif Viade == Wurple:

   print(“Viade and Wurple are both equal players”)

else:

print(“Wurple is slightly better than Viade”)

This should be the result of your code. Here is a screenshot I put in to help you:

 

Leave a Reply

Your email address will not be published. Required fields are marked *