21 Ec 034
21 Ec 034
phonebook = {
"Raj": "8747010488",
"Alice": "8088098227",
"Bob": "7349323784"
if key in phonebook:
else:
output:
2]
tuple1=['harshi'];
tuple2=['gowda'];
tuple3=tuple1+tuple2;
print(tuple3);
output:
['harshi', 'gowda']
4]
def copy_file(source,destination):
dest.write(src.read())
sfile='source.txt'
dfile='destination.txt'
copy_file(sfile,dfile)
5]
class Rectangle():
def __init__(self,l,w):
self.length=l
self.width=w
def rectangle_area(self):
return self.length*self.width
def rectangle_peri(self):
return 2*(self.length+self.width)
newRectangle=Rectangle(12,20)
print('area',newRectangle.rectangle_area())
print('perimeter',newRectangle.rectangle_peri())
output:
area 240
perimeter 64
6]
def count_vowels(sentence):
vowels = "aeiou"
count = 0
if char.lower() in vowels:
count += 1
return count
print(count_vowels(sentence))
output:8
7] num=[10,20,30,40]
print(num.index(40))
output:3
8]
n1, n2 = 0, 1
count = 0
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
output:
Fibonacci sequence:
13
9] import re
pattern = r'^[A-Z][a-z]+$'
for s in strings:
if re.match(pattern, s):
print(f"Matching: {s}")
else:
output:
Matching: Hello
Matching: Apple
Matching: Zebra