Skip to content

Commit 6ff014c

Browse files
committed
provided solution for Day 8
1 parent 37253f7 commit 6ff014c

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

solution22.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
3+
4+
Suppose the following input is supplied to the program:
5+
6+
New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.
7+
Then, the output should be:
8+
9+
2:2
10+
3.:1
11+
3?:1
12+
New:1
13+
Python:5
14+
Read:1
15+
and:1
16+
between:1
17+
choosing:1
18+
or:2
19+
to:1
20+
'''
21+
inputs = input().split()
22+
inputSet = sorted(set(inputs))
23+
24+
# print(inputSet)
25+
26+
for word in inputSet:
27+
print(f'{word}:{inputs.count(word)}')

solution23.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'''
2+
Write a method which can calculate square value of number
3+
'''
4+
5+
6+
def calculate_square(number):
7+
return number**2
8+
9+
print(calculate_square(6))

solution24.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Python has many built-in functions, and if you do not know how to use it, you can read document online or find some books. But Python has a built-in document function for every built-in functions.
3+
4+
Please write a program to print some Python built-in functions documents, such as abs(), int(), raw_input()
5+
6+
And add document for your own function
7+
'''
8+
9+
print(abs.__doc__)
10+
print(int.__doc__)
11+
print(input.__doc__)
12+
13+
14+
def my_func():
15+
'''
16+
This function demonstrates the use of docstring.
17+
'''
18+
return "This is a dummy function!"
19+
20+
print(my_func.__doc__)

solution25.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
Define a class, which have a class parameter and have a same instance parameter.
3+
'''
4+
5+
6+
class Car:
7+
doors = 2
8+
9+
def __init__(self, doors):
10+
self.doors = doors
11+
12+
myCar = Car(4)
13+
print(myCar.doors)

0 commit comments

Comments
 (0)