Skip to content

Commit bf03e2d

Browse files
committed
added solution for day 5
1 parent c4420f4 commit bf03e2d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

solution16.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers. >Suppose the following input is supplied to the program:
3+
4+
1,2,3,4,5,6,7,8,9
5+
Then, the output should be:
6+
7+
1,9,25,49,81
8+
'''
9+
10+
user_input = input()
11+
input_list = user_input.split(',')
12+
13+
# output_list = []
14+
# for item in input_list:
15+
# if int(item) % 2 != 0:
16+
# output_list.append(int(item) ** 2)
17+
# print(output_list)
18+
19+
output_list = [str(int(item)**2) for item in input_list if int(item) % 2 != 0]
20+
print(','.join(output_list))

solution17.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
Write a program that computes the net amount of a bank account based a transaction log from console input. The transaction log format is shown as following:
3+
4+
D 100
5+
W 200
6+
D means deposit while W means withdrawal.
7+
Suppose the following input is supplied to the program:
8+
9+
D 300
10+
D 300
11+
W 200
12+
D 100
13+
Then, the output should be:
14+
15+
500
16+
'''
17+
18+
amount = 0
19+
while True:
20+
log = input().split()
21+
if not log:
22+
break
23+
if 'D' == log[0]:
24+
amount += int(log[1])
25+
elif 'W' == log[0]:
26+
amount -= int(log[1])
27+
else:
28+
print("wrong log")
29+
print(amount)

0 commit comments

Comments
 (0)