-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_if_else.py
More file actions
50 lines (39 loc) · 1.09 KB
/
python_if_else.py
File metadata and controls
50 lines (39 loc) · 1.09 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
41
42
43
44
45
46
47
48
49
50
"""
Python If-Else
Task:
Given an integer, n, perform the following conditional actions:
- If n is odd, print Weird
- If n is even and in the inclusive range of 2 to 5, print Not Weird
- If n is even and in the inclusive range of 6 to 20, print Weird
- If n is even and greater than 20, print Not Weird
Input Format:
A single line containing a positive integer, n.
Constraints:
1 <= n <= 100
Output Format:
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input:
3
Sample Output:
Weird
Explanation:
n = 3
n is odd and odd numbers are weird, so we print Weird.
@author: Luísa Maria Mesquita
"""
def is_even(num):
if(num % 2 == 0):
return True
return False
def python_if_else():
n = int(input("Number: "))
if(n < 1 or n > 100):
return "Error!"
if(not is_even(n)):
print("Weird")
elif(is_even(n) and n >= 2 and n <= 5):
print("Not Weird")
elif(is_even(n) and n >= 6 and n <= 20):
print("Weird")
elif(is_even(n) and n > 20):
print("Not Weird")