0% found this document useful (0 votes)
37 views2 pages

Practice On If Condition

The document contains 5 code snippets that check if a number is positive, negative, or zero, and display the appropriate message. The first two snippets use if/else statements, the third uses nested if statements and gets user input. The fourth snippet compares two variables and prints a statement. The fifth snippet compares two equal variables and prints the appropriate statement.

Uploaded by

Manohar Datt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Practice On If Condition

The document contains 5 code snippets that check if a number is positive, negative, or zero, and display the appropriate message. The first two snippets use if/else statements, the third uses nested if statements and gets user input. The fourth snippet compares two variables and prints a statement. The fifth snippet compares two equal variables and prints the appropriate statement.

Uploaded by

Manohar Datt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

# Program checks if the number is positive or negative


# And displays an appropriate message

num = 3

# Try these two variations as well.


# num = -5
# num = 0

if num >= 0:
print("Positive or Zero")
else:
print("Negative number")

2. # In this program,
# we 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")

3. # In this program, we input a number


# check if the number is positive or
# negative or zero and display
# an appropriate message
# This time we use nested if

num = float(input("Enter a number: "))


if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
4. x,y =12,8

if(x < y):

st= "x is less than y"

print(st)

5. x,y =8,8

if(x < y):


st= "x is less than y"

elif (x == y):
st= "x is same as y"

else:
st="x is greater than y"
print(st)

You might also like