Skip to content

Commit 2a3b561

Browse files
authored
Merge pull request #24 from arsho/feature/python3
Feature/python3
2 parents f7b6bd9 + 7e6c276 commit 2a3b561

22 files changed

+265
-237
lines changed

BasicDataTypes/Findingthepercentage.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/finding-the-percentage/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
n=int(input())
11-
ar={}
12-
for i in range(0,n):
13-
s=input()
14-
ss=s.split(" ")
15-
n=ss[0]
16-
m1=float(ss[1])
17-
m2=float(ss[2])
18-
m3=float(ss[3])
19-
m_avg=(m1+m2+m3)/3.0
20-
ar[n]="%.2f" % m_avg
21-
s_name=input()
22-
print(ar[s_name])
9+
if __name__ == '__main__':
10+
n = int(input())
11+
student_marks = {}
12+
for _ in range(n):
13+
name, *line = input().split()
14+
scores = list(map(float, line))
15+
student_marks[name] = scores
16+
query_name = input()
17+
res = sum(student_marks[query_name])/len(student_marks[name])
18+
print("{:.2f}".format(res))
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
'''
2-
Title : Find the Second Largest Number
2+
Title : Find the Runner-Up Score!
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
n=int(raw_input())
11-
num_str_ar=raw_input().strip().split()
12-
13-
num_ar=list(map(int,num_str_ar))
14-
set_tmp=set(num_ar)
15-
final_ar=list(set_tmp)
16-
final_ar.sort()
17-
print final_ar[-2]
9+
if __name__ == '__main__':
10+
n = int(input())
11+
arr = map(int, input().split())
12+
print(sorted(set(arr), reverse=True)[1])

BasicDataTypes/ListComprehensions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/list-comprehensions/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
x=int(raw_input())
11-
y=int(raw_input())
12-
z=int(raw_input())
13-
n=int(raw_input())
14-
print([ [i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k != n ])
9+
if __name__ == '__main__':
10+
x = int(input())
11+
y = int(input())
12+
z = int(input())
13+
n = int(input())
14+
ar = [[i, j, k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k!=n]
15+
print(ar)

BasicDataTypes/Lists.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,38 @@
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/python-lists/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
ar=[]
11-
n=int(input())
12-
for i in range(0,n):
13-
tmp_str=input()
14-
tmp_str_ar=tmp_str.strip().split(" ")
15-
cmd=tmp_str_ar[0]
16-
if(cmd=="print"):
17-
print(ar)
18-
elif(cmd=="sort"):
19-
ar.sort()
20-
elif(cmd=="reverse"):
21-
ar.reverse()
22-
elif(cmd=="pop"):
23-
ar.pop()
24-
elif(cmd=="count"):
25-
val=int(tmp_str_ar[1])
26-
ar.count(val)
27-
elif(cmd=="index"):
28-
val=int(tmp_str_ar[1])
29-
ar.index(val)
30-
elif(cmd=="remove"):
31-
val=int(tmp_str_ar[1])
32-
ar.remove(val)
33-
elif(cmd=="append"):
34-
val=int(tmp_str_ar[1])
35-
ar.append(val)
36-
elif(cmd=="insert"):
37-
pos=int(tmp_str_ar[1])
38-
val=int(tmp_str_ar[2])
39-
ar.insert(pos,val)
9+
10+
if __name__ == '__main__':
11+
N = int(input())
12+
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]
17+
if cmd == "print":
18+
print(ar)
19+
elif cmd == "sort":
20+
ar.sort()
21+
elif cmd == "reverse":
22+
ar.reverse()
23+
elif cmd == "pop":
24+
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)
31+
elif cmd == "remove":
32+
val = int(tmp_str_ar[1])
33+
ar.remove(val)
34+
elif cmd == "append":
35+
val = int(tmp_str_ar[1])
36+
ar.append(val)
37+
elif cmd == "insert":
38+
pos = int(tmp_str_ar[1])
39+
val = int(tmp_str_ar[2])
40+
ar.insert(pos, val)

BasicDataTypes/NestedLists.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,18 @@
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/nested-list/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
from collections import OrderedDict
11-
12-
n=int(raw_input())
13-
ar={}
14-
val_ar=[]
15-
for i in range(0,n):
16-
tmp_name=raw_input()
17-
tmp_marks=float(raw_input())
18-
ar[tmp_name]=tmp_marks
19-
val_ar.append(tmp_marks)
20-
21-
set_val=set(val_ar)
22-
val_ar=list(set_val)
23-
val_ar.sort()
24-
sec_mark=val_ar[1]
25-
##print sec_mark
26-
final_ar=[]
27-
for i in ar:
28-
if(sec_mark==ar[i]):
29-
final_ar.append(i)
30-
31-
final_ar.sort()
32-
for i in final_ar:
33-
print i
9+
if __name__ == '__main__':
10+
students = []
11+
scores = []
12+
for _ in range(int(input())):
13+
name = input()
14+
score = float(input())
15+
student = [name, score]
16+
students.append(student)
17+
scores.append(score)
18+
second_min_score = sorted(set(scores))[1]
19+
filtered_student_names = sorted([student[0] for student in students if student[1] == second_min_score])
20+
print("\n".join(filtered_student_names))

BasicDataTypes/Tuples.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
Subdomain : Data Types
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/python-tuples/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
n=int(raw_input())
11-
numbers=raw_input().strip().split()
12-
ar=[]
13-
for i in range(0,len(numbers)):
14-
ar.append(int(numbers[i]))
15-
t=tuple(ar)
16-
print hash(t)
9+
if __name__ == '__main__':
10+
n = int(input())
11+
integer_list = map(int, input().split())
12+
t = tuple(integer_list)
13+
print(hash(t))

Introduction/ArithmeticOperators.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Subdomain : Introduction
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 15 April 2020
77
Problem : https://www.hackerrank.com/challenges/python-arithmetic-operators/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
a=int(raw_input())
11-
b=int(raw_input())
12-
print a+b
13-
print a-b
14-
print a*b
9+
if __name__ == '__main__':
10+
a = int(input())
11+
b = int(input())
12+
print(a+b)
13+
print(a-b)
14+
print(a*b)

Introduction/Loops.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
Subdomain : Introduction
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 13 May 2020
77
Problem : https://www.hackerrank.com/challenges/python-loops/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
a=int(raw_input())
11-
for i in range(0,a):
12-
print i*i
9+
if __name__ == '__main__':
10+
n = int(input())
11+
for i in range(n):
12+
print(i*i)
13+

Introduction/PrintFunction.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
Subdomain : Introduction
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/python-print/problem
88
'''
9-
n=int(input())
10-
ar=range(1,n+1)
11-
for i in ar:
12-
print(i,end="")
9+
10+
if __name__ == '__main__':
11+
n = int(input())
12+
ar=range(1,n+1)
13+
for i in ar:
14+
print(i,end="")
15+
16+
"""
17+
Alternate solution:
18+
19+
if __name__ == '__main__':
20+
n = int(input())
21+
print("".join([str(i) for i in range(1,n+1)]))
22+
23+
"""

Introduction/PythonDivision.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Subdomain : Introduction
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 06 July 2020
77
Problem : https://www.hackerrank.com/challenges/python-division/problem
88
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
a=int(raw_input())
11-
b=int(raw_input())
12-
print a/b
13-
c=float(a)
14-
print c/b
9+
if __name__ == '__main__':
10+
a = int(input())
11+
b = int(input())
12+
print(a//b)
13+
print(a/b)
14+

0 commit comments

Comments
 (0)