Skip to content

Commit 7bf6fde

Browse files
committed
solved problems 24 to 28
1 parent aaab842 commit 7bf6fde

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

Chapter 6/problems/Problem6_24.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def names():
2+
dic = {}
3+
while True:
4+
name = input('Enter next name:')
5+
if name == '':
6+
for keys in dic.keys():
7+
print('There is {} student named {}'.format(dic[keys],keys))
8+
if name in dic.keys():
9+
dic[name] += 1
10+
else:
11+
dic[name] = 1
12+

Chapter 6/problems/Problem6_25.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def different(table):
2+
distinc = set()
3+
for i in range(len(table)):
4+
for a in range(len(table[i])):
5+
distinc.add(table[i][a])
6+
return len(distinc)

Chapter 6/problems/Problem6_26.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def week():
2+
weekdays = {'Mo':'Monday', 'Tu':'Tuesday', 'We':'Wednesday', 'Th':'Thursday',
3+
'Fr':'Friday', 'Sa':'Saturday', 'Su':'Sunday'}
4+
while True:
5+
ab = input('Enter day abbreviation:')
6+
print(weekdays[ab])

Chapter 6/problems/Problem6_27.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def index(filename, listwords):
2+
file = open(filename)
3+
content = file.read()
4+
file.close()
5+
content = content.splitlines()
6+
worddict = {}
7+
for word in listwords:
8+
for i in range(len(content)):
9+
if word in content[i]:
10+
if word in worddict.keys():
11+
worddict[word] += ', '+ str(i+1)
12+
else:
13+
worddict[word] = str(i+1)
14+
15+
for key in worddict.keys():
16+
print('{:10} {:10}'.format(key,worddict[key]))
17+
18+
19+

Chapter 6/problems/Problem6_28.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def translate(dic):
2+
while True:
3+
trans = ''
4+
phrase = input('Entre the phrase:')
5+
phrase = phrase.split()
6+
for word in phrase:
7+
if word in dic.keys():
8+
trans += dic[word] + ' '
9+
else:
10+
trans += '____ '
11+
print(trans)

0 commit comments

Comments
 (0)