Skip to content

Commit c462100

Browse files
committed
Updated BasicDataTypes solutions
1 parent fabae97 commit c462100

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

BasicDataTypes/Findingthepercentage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 06 July 2020
7+
Updated : 06 February 2023
78
Problem : https://www.hackerrank.com/challenges/finding-the-percentage/problem
89
"""
910
if __name__ == '__main__':
@@ -14,5 +15,6 @@
1415
scores = list(map(float, line))
1516
student_marks[name] = scores
1617
query_name = input()
17-
res = sum(student_marks[query_name]) / len(student_marks[name])
18-
print("{:.2f}".format(res))
18+
avg_score = sum(student_marks[query_name]) / len(student_marks[query_name])
19+
print(f"{avg_score:.2f}")
20+

BasicDataTypes/ListComprehensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
y = int(input())
1212
z = int(input())
1313
n = int(input())
14-
ar = [[i, j, k] for i in range(x + 1) for j in range(y + 1) for k in
15-
range(z + 1) if i + j + k != n]
14+
ar = [[i, j, k] for i in range(x + 1) for j in range(y + 1)
15+
for k in range(z + 1) if i + j + k != n]
1616
print(ar)

BasicDataTypes/Lists.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 06 July 2020
7+
Updated : 06 February 2023
78
Problem : https://www.hackerrank.com/challenges/python-lists/problem
89
"""
910

1011
if __name__ == '__main__':
1112
N = int(input())
1213
ar = []
13-
for i in range(0, N):
14-
tmp_str = input()
15-
tmp_str_ar = tmp_str.strip().split(" ")
16-
cmd = tmp_str_ar[0]
14+
for i in range(N):
15+
command_args = input().strip().split(" ")
16+
cmd = command_args[0]
1717
if cmd == "print":
1818
print(ar)
1919
elif cmd == "sort":
@@ -22,19 +22,13 @@
2222
ar.reverse()
2323
elif cmd == "pop":
2424
ar.pop()
25-
elif cmd == "count":
26-
val = int(tmp_str_ar[1])
27-
ar.count(val)
28-
elif cmd == "index":
29-
val = int(tmp_str_ar[1])
30-
ar.index(val)
3125
elif cmd == "remove":
32-
val = int(tmp_str_ar[1])
26+
val = int(command_args[1])
3327
ar.remove(val)
3428
elif cmd == "append":
35-
val = int(tmp_str_ar[1])
29+
val = int(command_args[1])
3630
ar.append(val)
3731
elif cmd == "insert":
38-
pos = int(tmp_str_ar[1])
39-
val = int(tmp_str_ar[2])
32+
pos = int(command_args[1])
33+
val = int(command_args[2])
4034
ar.insert(pos, val)

BasicDataTypes/NestedLists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
students.append(student)
1717
scores.append(score)
1818
second_min_score = sorted(set(scores))[1]
19-
student_names = sorted(
20-
[student[0] for student in students if student[1] == second_min_score])
19+
student_names = sorted([student[0] for student in students
20+
if student[1] == second_min_score])
2121
print("\n".join(student_names))

0 commit comments

Comments
 (0)