Skip to content

Commit 2467ec1

Browse files
committed
Day5 added
1 parent b05c96d commit 2467ec1

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

Day5/average_word_length.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Takes in a string, figure out the average length of all the words and return a number representing the average length. Remove all punctuation. Round up to the nearest whole number.
3+
4+
Input Format:
5+
A string containing multiple words. Input: What a drag Shikamaru
6+
7+
Output Format:
8+
A number representing the average length of each word, rounded up to the nearest whole number. Output: 5
9+
10+
Explanation:
11+
The string in question has 4 words with a total of 18 letters (spaces do not count). The average word length is 4.50 letters, rounding it up to the nearest whole numbers results in 5.
12+
"""
13+
import math
14+
import string
15+
data = input().split(' ')
16+
avg_word = []
17+
for calc in data:
18+
for check in calc:
19+
if check in string.punctuation:
20+
pass
21+
else:
22+
avg_word.append(check)
23+
24+
print(math.ceil(len(avg_word)/len(data)))

Day5/dejavu.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def dejavu(text):
2+
count=0
3+
new=list()
4+
for i in text:
5+
if i not in new:
6+
new.append(i)
7+
else:
8+
count=1
9+
return count
10+
11+
word=list(input())
12+
count=dejavu(word)
13+
if count==1:
14+
print('Deja Vu')
15+
else:
16+
print('Unique')

Day5/intro_to_enumerate.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Introduction to Enumerate
2+
3+
Before knowing Enumerate lets look into an example as usual. Consider a List and print the elements of the list with their index number.
4+
```py
5+
>>> myanimelist = ["One Piece","Gintama","Attack On Titan","Code Geass","Monster"]
6+
7+
>>> for i in range(len(myanimelist)):
8+
... print(i+1,myanimelist[i])
9+
...
10+
1 One Piece
11+
2 Gintama
12+
3 Attack On Titan
13+
4 Code Geass
14+
5 Monster
15+
```
16+
17+
The same code lets code it with enumerate.
18+
19+
```py
20+
>>> for index,anime in enumerate(myanimelist,1):
21+
... print("{}:{}".format(index,anime))
22+
...
23+
1:One Piece
24+
2:Gintama
25+
3:Attack On Titan
26+
4:Code Geass
27+
5:Monster
28+
29+
>>> for index,anime in enumerate(myanimelist):
30+
... print("{}:{}".format(index,anime))
31+
32+
33+
0:One Piece
34+
1:Gintama
35+
2:Attack On Titan
36+
3:Code Geass
37+
4:Monster
38+
```
39+
40+
``Enumerate`` makes our job easy by taking both index and values in one go. Understanding enumerate is easy. We have taken two examples in enumerate function. Enumerate takes two parameters, the first parameter is the iterable sequence such as lists, string, range. And the second parameter is the start index includes a integer value.

Day5/piglatin.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Program 1: Piglatin
3+
4+
Input Format
5+
A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization), e.g., "nevermind you’ve got them"
6+
7+
Output Format
8+
A string of the same sentence in Pig Latin.
9+
e.g., output: "evermindnay ouveyay otgay hemtay"
10+
11+
Explanation
12+
The output should be the original sentence with each word changed so that they first letter is at the end and then -ay is added after that.
13+
"""
14+
15+
word=input().lower().split()
16+
new=[]
17+
for i in word:
18+
k=i[1:]+i[0]+'ay'
19+
new.append(k)
20+
print(' '.join(new))
21+
22+
#or
23+
"""
24+
import string
25+
l=input('Enter a text:').lower().split()
26+
new=[]
27+
punc=string.punctuation
28+
for i in l:
29+
for j in i:
30+
if j in punc:
31+
del j
32+
else:
33+
new.append(j)
34+
k=''.join(new)
35+
new.append(' ')
36+
37+
print(len(''.join(k.rstrip())))
38+
"""

0 commit comments

Comments
 (0)