-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditionals_demo.py
104 lines (81 loc) · 2.02 KB
/
conditionals_demo.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
# only if
if condition1 :
executes when the condition1 is true
# if else
if condition1 :
executes when the condition1 is true
else :
executes when the condition1 is false
#if elif else ladder
if condition1 :
executes when the condition1 is true
elif condition2 :
executes when the condition2 is true and condition1 is false
else :
executes when the both condition1 and condition2 is false
"""
"""
if the number is divisible by 3 print Fizz
if the number is divisible by 5 print Buzz
if the number is divisible by 3 and also divisible by 5 print Fizz Buzz
Testcase :
21 --> Fizz
50 --> Buzz
15 --> Fizz Buzz
22 --> Invalid Input
"""
# # solution1
# input_num = int(input("please enter a number"))
# remainder_from_3 = input_num%3
# remainder_from_5 = input_num%5
# if remainder_from_3==0 and remainder_from_5 ==0 :
# print(" Fizz Buzz")
# elif remainder_from_3 == 0 :
# print("Fizz")
# elif remainder_from_5 == 0 :
# print("Buzz")
# # solution2
# num = int(input("Please enter the number"))
# if num %5==0 and num % 3 ==0 :
# print("Fizz Buzz")
# elif num%3 == 0 :
# print("Fizz")
# elif num%5 == 0 :
# print("Buzz")
# else:
# print("Invalid Input")
# # solution3
# num = int(input("Please enter the number"))
# if num %5==0 :
# if num % 3 ==0 :
# print("Fizz Buzz")
# else:
# print("Buzz")
# elif num%3 == 0 :
# print("Fizz")
# else:
# print("Invalid Input")
# # solution4
# num = int(input("Please enter the number"))
# if num %3==0 :
# if num % 5 ==0 :
# print("Fizz Buzz")
# else:
# print("Fizz")
# elif num%5 == 0 :
# print("Buzz")
# else:
# print("Invalid Input")
# solution5
num = int(input("Please enter the number"))
# very specific to python
is_inside_if_clause = 'N'
if num%3 == 0 :
print("Fizz",end = ' ' )
is_inside_if_clause = 'Y'
if num%5 == 0 :
print("Buzz")
is_inside_if_clause = 'Y'
if is_inside_if_clause != 'Y':
print("Invalid Input")