-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.py
More file actions
23 lines (18 loc) · 697 Bytes
/
22.py
File metadata and controls
23 lines (18 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Program No. : 22
Program : To check whether number is positive or negative.
def check_number_sign():
print("--- Positive or Negative Checker ---")
try:
# 1. Get input from the user (float handles decimals too)
number = float(input("Enter any number: "))
# 2. Check the condition
if number > 0:
print(f"The number **{number}** is **Positive**.")
elif number < 0:
print(f"The number **{number}** is **Negative**.")
else:
print("The number is **Zero**.")
except ValueError:
print("Error: Invalid input. Please enter a valid numerical value.")
# Run the program
check_number_sign()