-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_05.py
More file actions
75 lines (45 loc) · 1.33 KB
/
05_05.py
File metadata and controls
75 lines (45 loc) · 1.33 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''
Understanding super() and __init__()
Parent - Child Class relations
'''
class Hello:
def __init__(self, name, age):
self.name = name
self.age = age
print(f'{self.name} is {self.age}')
class Hi(Hello):
def __init__(self, name, age, country, job):
super().__init__(name,age)
self.country = country
self.job = job
print(f'{self.name} lives in {self.country}, is {self.age} years and works as a {self.job}')
if __name__ == "__main__":
language = Hi('Bob', 35, 'USA', 'Software Engineer')
print(language)
#print(intro)
'''
A Palindrome Checker
'''
import re
string = input("Enter a word or a phrase: ")
new_string = re.sub(r'\W+', '', string.lower())
reversed_string = new_string[::-1]
if new_string == reversed_string:
print(f"{new_string} is a palindrome")
else:
print(f"{new_string} is not a palindrome")
'''
A Fibonacci Sequence Generator
'''
def fib(num):
fib_sequence = {}
for i in range(1, num + 1):
if i <= 2:
fib_sequence[i] = 1
else:
fib_sequence[i] = fib_sequence[i - 1] + fib_sequence[i - 2]
return fib_sequence
if __name__ == "__main__":
n = int(input("Enter the number of Fibonacci numbers to generate: "))
fib1 = fib(n)
print(fib1)