Skip to content

Commit bbbbe0d

Browse files
authored
Update Day_12.md
1 parent 69e4a41 commit bbbbe0d

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Status/Day_12.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,69 @@
1+
# Question 44
2+
### Level 1
3+
4+
**Question:**
5+
***Write a program which can map() to make a list whose elements are square of numbers between 1 and 20 (both included).***
6+
7+
---------------
8+
9+
### Hints: Use map() to generate a list. Use lambda to define anonymous functions.
10+
---------------
11+
12+
**Main Author's Solution: Python 2**
13+
```
14+
squaredNumbers = map(lambda x: x**2, range(1,21))
15+
print squaredNumbers
16+
```
17+
**My Solution: Python 3**
18+
```
19+
```
20+
----------------------------------------
21+
22+
# Question 45
23+
### Level 1
24+
25+
**Question:**
26+
***Define a class named American which has a static method called printNationality.***
27+
28+
---------------------
29+
### Hints: Use @staticmethod decorator to define class static method.
30+
---------------------
31+
**Main Author's Solution: Python 2**
32+
```
33+
class American(object):
34+
@staticmethod
35+
def printNationality():
36+
print "America"
37+
38+
anAmerican = American()
39+
anAmerican.printNationality()
40+
American.printNationality()
41+
```
42+
**My Solution: Python 3**
43+
```
44+
```
45+
----------------------------------------
46+
47+
7.2
48+
49+
Question:
50+
Define a class named American and its subclass NewYorker.
51+
52+
Hints:
53+
54+
Use class Subclass(ParentClass) to define a subclass.
55+
56+
Solution:
57+
58+
class American(object):
59+
pass
60+
61+
class NewYorker(American):
62+
pass
63+
64+
anAmerican = American()
65+
aNewYorker = NewYorker()
66+
print anAmerican
67+
print aNewYorker
68+
169

0 commit comments

Comments
 (0)