Skip to content

Commit d7ecb57

Browse files
authored
Add files via upload
1 parent d7d5e0e commit d7ecb57

17 files changed

+156
-0
lines changed

hackerrank/Problem Solving (Advanced)/README.md

Whitespace-only changes.

hackerrank/Problem Solving (Basic)/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if __name__ == '__main__':
2+
a = int(input())
3+
b = int(input())
4+
print(a+b)
5+
print(a-b)
6+
print(a*b)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
arr = map(int, input().split())
4+
5+
# Removing duplicates from the list
6+
new_arr = list(set(arr))
7+
8+
# Sorting the list
9+
new_arr.sort()
10+
11+
# Printing the the second last element
12+
print(new_arr[-2])
13+
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Finding The Percentage HackerRank challenge
2+
# Tasks
3+
# The provided code stub read in a dictionary containing key/value pairs of name:[Marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal.
4+
5+
# Dictionaries are used to store data values in key:value pairs.
6+
# List items are ordered, changeable, and allow duplicate values.
7+
# [name, * line] This allows you to handle variable-length input where you want to assign the first word to name and the rest of the words to line regardless of their number.
8+
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+
# My solution
18+
19+
print( "%.2f" % (sum(list(student_marks[query_name])) / (len(list(student_marks[query_name])))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if __name__ == '__main__':
2+
x = int(input())
3+
y = int(input())
4+
z = int(input())
5+
n = int(input())
6+
7+
perm = []
8+
for i in range(x+1):
9+
for j in range(y+1):
10+
for k in range(z+1):
11+
if (i+j+k)!=n:
12+
perm.append([i,j,k])
13+
14+
print(perm)
15+
16+
# Method 2
17+
# arr = [[X, Y, Z] for X in range(x+1) for Y in range(y+1) for Z in range(z+1) if X + Y + Z != N]

hackerrank/Python (Basic)/Lists.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if __name__ == '__main__':
2+
N = int(input())
3+
arr = []
4+
for _ in range(N):
5+
command = input().split()
6+
if command[0] == "insert":
7+
arr.insert(int(command[1]),int(command[2]))
8+
elif command[0] == "remove":
9+
arr.remove(int(command[1]))
10+
elif command[0] == "append":
11+
arr.append(int(command[1]))
12+
elif command[0] == "sort":
13+
arr.sort()
14+
elif command[0] == "pop":
15+
arr.pop()
16+
elif command[0] == "reverse":
17+
arr.reverse()
18+
elif command[0] == "print":
19+
print(arr)
20+
else :
21+
continue

hackerrank/Python (Basic)/Loops.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
4+
for i in range(n):
5+
print(i*i)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
records = []
4+
scores = []
5+
out = []
6+
for _ in range(n):
7+
name = input()
8+
score = float(input())
9+
records.append([name, score])
10+
scores.append(score)
11+
12+
# Removing duplicates from the list
13+
new_scores = list(set(scores))
14+
# Sorting the list
15+
new_scores.sort()
16+
# crete a new list : studens having lowest grade
17+
for i in range(n):
18+
if new_scores[1]==records[i][1]:
19+
out.append(records[i])
20+
# order names alphabetically in the new_scores
21+
new_out = sorted(out)
22+
for i in range(len(new_out)):
23+
print(new_out[i][0])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
4+
for i in range(n):
5+
print(i+1, end="")
6+
7+
# Print without newline (end="")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if __name__ == '__main__':
2+
a = int(input())
3+
b = int(input())
4+
5+
# The result of the integer division 3//5 = 0
6+
# The result of the float divison 3/5 = 0.6
7+
print(a//b)
8+
print(a/b)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import math
2+
3+
4+
if __name__ == '__main__':
5+
n = int(input().strip())
6+
7+
if n % 2 == 1:
8+
print("Weird")
9+
elif n >=2 and n <=5:
10+
print("Not Weird")
11+
elif n <= 20:
12+
print("Weird")
13+
else:
14+
print("Not Weird")

hackerrank/Python (Basic)/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def split_and_join(line):
2+
return "-".join(line.split())
3+
4+
if __name__ == '__main__':
5+
line = input()
6+
result = split_and_join(line)
7+
print(result)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The year can be evenly divided by 4, is a leap year, unless:
2+
# The year can be evenly divided by 100, it is NOT a leap year, unless:
3+
# The year is also evenly divisible by 400. Then it is a leap year.
4+
5+
def is_leap(year):
6+
leap = False
7+
8+
if (year%4==0 and year%100!=0) or year%400==0:
9+
leap=True
10+
11+
return leap
12+
13+
year = int(input())
14+
print(is_leap(year))

hackerrank/Python (Intermediate)/README.md

Whitespace-only changes.

hackerrank/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> ## [HackerRank-python](https://www.hackerrank.com/domains/python?badge_type=python)

0 commit comments

Comments
 (0)