Python if..if-else and conditional statements: examples and usage, Slides of Object Oriented Programming

Python code examples and explanations of the if, if-else, if-elif, and nested if statements. It covers how to test variables for different conditions and print corresponding outputs.

Typology: Slides

2019/2020

Uploaded on 08/07/2020

muskan278
muskan278 🇮🇳

4

(1)

5 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
if..if-else..if-elif in Python
July 29, 2019
In [1]: a=5
In [2]: if a>0:
print("Positive")
else:
print("Negative")
Positive
In [5]: x=int(input())
if x>0:
print("Positive")
elif x<0:
print("Negative")
else:
print("Zero")
-9
Negative
In [6]: day =int(input())
if day == 1:
print("Monday")
elif day == 2:
print("Tuesday")
elif day == 3:
print("Wednesday")
elif day == 4:
print("Thursday")
elif day == 5:
print("Friday")
elif day == 6:
print("Saturday")
else:
print("Sunday")
1
pf2

Partial preview of the text

Download Python if..if-else and conditional statements: examples and usage and more Slides Object Oriented Programming in PDF only on Docsity!

if..if-else..if-elif in Python

July 29, 2019

In [1]: a=

In [2]: if a>0: print("Positive") else: print("Negative")

Positive

In [5]: x = int(input()) if x>0: print("Positive") elif x<0: print("Negative") else: print("Zero")

Negative

In [6]: day = int(input()) if day == 1: print("Monday") elif day == 2: print("Tuesday") elif day == 3: print("Wednesday") elif day == 4: print("Thursday") elif day == 5: print("Friday") elif day == 6: print("Saturday") else: print("Sunday")

Thursday

In [7]: x = int(input()) y = int(input()) if x>y: print("X is greater than Y") else: print("Y is greater than X")

5 9 Y is greater than X

In [11]: x = int(input()) y = int(input()) z = int(input()) if x>y: if x>z: print("X is the greatest") else: print("Z is the greatest") else: if y>z: print("Y is the greatest") else: print("Z is the greatest")

5 8 Z is the greatest