Examples of if... else in Python programming
All Contributions
Program to check if x = 4 and prints a message to tell the user that if it's or is not :
x = 3
if x == 4:
print("Yes")
else:
print("No")
Program to input a number and check if the number is positive or negative or zero and display an appropriate message :
This time we use nested if statement''
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
program to check if the number is positive or negative or zero and display an appropriate message :
num = 3.4
# Try these two variations as well:
# num = 0
# num = -4.5
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
total contributions (6)
Program to tell the user wich letter he choose :