Docsity

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

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