-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_If_Else.py
More file actions
52 lines (43 loc) · 1.4 KB
/
Copy path04_If_Else.py
File metadata and controls
52 lines (43 loc) · 1.4 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
51
52
# print number from 1 till 100
# if number is div by 3 print Fizz,
# if number is div by 5 Buzz
# if both then FizzBuzz
# else number it self.
from sre_parse import fix_flags
class FizzBuzz:
def first_function(self):
for n in range(1,101) :
if n%15 == 0:
print('FizzBuzz')
else:
if n % 3 == 0:
print('Fizz')
else:
if n%5 == 0 :
print('Buzz')
else:
print(n)
def second_function(self):
for n in range(1, 101):
if n % 15 == 0:
print('FizzBuzz')
elif n % 3 == 0:
print('Fizz')
elif n % 5 == 0:
print('Buzz')
else:
print(n)
def third_function(self):
n = 3
print('Fizz' if n % 3 == 0 else n)
n = 5
print('Buzz' if n % 5 == 0 else n)
# This is ternary operator in Python, but its recommended to use the 'elif' instead of this as this is hard for readabilty purpose.
print(['FizzBuzz' if n % 15 == 0 else 'Fizz' if n % 3 == 0 else 'Buzz' if n % 5 ==0 else n for n in range(1,101)])
fizzBuzz = FizzBuzz()
print('First Function')
fizzBuzz.first_function()
print('Second Function')
fizzBuzz.second_function()
print('Third Function')
fizzBuzz.third_function()