-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.positive_or_negative_integer.py
More file actions
40 lines (31 loc) · 1 KB
/
1.positive_or_negative_integer.py
File metadata and controls
40 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Python Program to check if a Number Is Positive Or Negative
# Method 1: Using Brute Force
# This method uses Brute Force to check whether a given integer is Positive or Negative.
num=16
if num>0:
print(f'{num} is a positive integer '.format(num))
elif num<0:
print(f'{num} is a negative integer '.format(num))
else:
print('Zero')
# Method 2: Using Nested if-else Statements
# This method uses a nested if-else Statements to check whether a given number is Positive or Negative.
if num>=0:
if num==0:
print('Zero')
else:
print(f'{num} is a positive integer '.format(num))
else:
print(f'{num} is a negative integer '.format(num))
# Method 3: Using Ternary Operator
# This method uses a ternary operator to check whether a number is Positive or Negative.
num=0
# print("Positive" if num>=0 else "Negative")
print("Positive" if num>0 else "Negative" if num<0 else "zero")
if num>0:
print("positive")
else:
if num<0:
print("negative")
else:
print("zero")