-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDay_09.py
More file actions
164 lines (131 loc) · 2.29 KB
/
Copy pathDay_09.py
File metadata and controls
164 lines (131 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
# coding: utf-8
# # Question 26
#
# ### **Question:**
#
# > **_Define a function which can compute the sum of two numbers._**
#
# ---
#
# ### Hints:
#
# > **_Define a function with two numbers as arguments. You can compute the sum in the function and return the value._**
#
# ---
#
#
#
# **Solutions:**
# In[1]:
sum = lambda n1, n2: n1 + n2 # here lambda is use to define little function as sum
print(sum(1, 2))
# ---
#
# # Question 27
#
# ### **Question:**
#
# > **_Define a function that can convert a integer into a string and print it in console._**
#
# ---
#
# ### Hints:
#
# > **_Use str() to convert a number to string._**
#
# ---
#
#
#
# **Solutions:**
# In[2]:
conv = lambda x: str(x)
n = conv(10)
print(n)
print(type(n)) # checks the type of the variable
# ---
#
# # Question 28
#
# ### **Question:**
#
# > **_Define a function that can receive two integer numbers in string form and compute their sum and then print it in console._**
#
# ---
#
# ### Hints:
#
# > **_Use int() to convert a string to integer._**
#
# ---
#
#
#
# **Solutions:**
# In[3]:
sum = lambda s1, s2: int(s1) + int(s2)
print(sum("10", "45")) # 55
# ---
#
# # Question 29
#
# ### **Question:**
#
# > **_Define a function that can accept two strings as input and concatenate them and then print it in console._**
#
# ---
#
# ### Hints:
#
# > **_Use + sign to concatenate the strings._**
#
# ---
#
#
#
# **Solutions:**
# In[4]:
sum = lambda s1, s2: s1 + s2
print(sum("10", "45")) # 1045
# ---
#
# # Question 30
#
# ### **Question:**
#
# > **_Define a function that can accept two strings as input and print the string with maximum length in console. If two strings have the same length, then the function should print all strings line by line._**
#
# ---
#
# ### Hints:
#
# > **_Use len() function to get the length of a string._**
#
# ---
#
#
#
# **Solutions:**
# In[5]:
def printVal(s1, s2):
len1 = len(s1)
len2 = len(s2)
if len1 > len2:
print(s1)
elif len1 < len2:
print(s2)
else:
print(s1)
print(s2)
s1, s2 = input().split()
printVal(s1, s2)
# ---
# In[6]:
"""Solution by: yuan1z"""
func = (
lambda a, b: print(max((a, b), key=len))
if len(a) != len(b)
else print(a + "\n" + b)
)
# ---