Skip to content

Commit 4c90302

Browse files
committed
just started
1 parent afe9ea2 commit 4c90302

14 files changed

+476
-0
lines changed

Diff for: 1 Introduction/Arithmetic Operators.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if __name__ == '__main__':
2+
a = int(input())
3+
b = int(input())
4+
print(a+b)
5+
print(a-b)
6+
print(a*b)
7+
"""
8+
Editorial by DOSHI
9+
We can solve this problem by using basic arithmetic operators like +, - and *.
10+
11+
Tested by DOSHI
12+
Problem Tester's code:
13+
14+
Python 2
15+
16+
a = int(raw_input())
17+
b = int(raw_input())
18+
19+
print a + b
20+
print a - b
21+
print a * b
22+
Python 3
23+
24+
a = int(input())
25+
b = int(input())
26+
27+
print(a + b)
28+
print(a - b)
29+
print(a * b)
30+
"""

Diff for: 1 Introduction/Loops.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
for i in range (n):
4+
print(i*i)
5+
"""
6+
Editorial by DOSHI
7+
Use loops to iterate over the range.
8+
9+
Tested by DOSHI
10+
Problem Tester's code:
11+
12+
for i in range(int(raw_input())):
13+
print i**2
14+
15+
"""

Diff for: 1 Introduction/Print Function.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
for i in range(n):
4+
print (i+1, end='')
5+
"""
6+
Editorial by DOSHI
7+
Using the map() and the print _function, we can solve this in one line.
8+
9+
Set by shashank21j
10+
Problem Setter's code:
11+
12+
Python 2
13+
14+
from __future__ import print_function
15+
print(*range(1, input() + 1), sep="")
16+
Python 3
17+
18+
print(*range(1, int(input()) + 1), sep="")
19+
Tested by DOSHI
20+
Problem Tester's code:
21+
22+
Python 2
23+
24+
from __future__ import print_function
25+
map(lambda x: print(x + 1,end=''), range(input()))
26+
Python 3
27+
28+
list(map(lambda x:print(x + 1, end=''), range(int(input()))))
29+
"""

Diff for: 1 Introduction/Python If-Else.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
10+
11+
if __name__ == '__main__':
12+
n = int(input().strip())
13+
if((n%2==1) or ( n%2 == 0 and n >= 6 and n <= 20 )):
14+
print("Weird")
15+
elif((n>=2 and n <= 5) or (n>20) ):
16+
print("Not Weird")
17+
"""
18+
Set by shashank21j
19+
Problem Setter's code:
20+
21+
Python 2
22+
23+
n = int(raw_input())
24+
if n % 2 == 1:
25+
print "Weird"
26+
elif n % 2 == 0 and 2 <= n <= 5:
27+
print "Not Weird"
28+
elif n % 2 == 0 and 6 <= n <= 20:
29+
print "Weird"
30+
else:
31+
print "Not Weird"
32+
Python 3
33+
34+
n = int(input())
35+
if n % 2 == 1:
36+
print("Weird")
37+
elif n % 2 == 0 and 2 <= n <= 5:
38+
print("Not Weird")
39+
elif n % 2 == 0 and 6 <= n <= 20:
40+
print("Weird")
41+
else:
42+
print("Not Weird")
43+
"""

Diff for: 1 Introduction/Python- Division.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
if __name__ == '__main__':
2+
a = int(input())
3+
b = int(input())
4+
print(int(a/b))
5+
print(float(a/b))
6+
"""
7+
Editorial by DOSHI
8+
In Python 2, __future__ module includes a new type of division called integer division given by the operator //
9+
10+
11+
12+
Now / performs float division and // performs integer division.
13+
14+
Tested by DOSHI
15+
Problem Tester's code:
16+
17+
Python 2
18+
19+
from __future__ import division
20+
a = int(raw_input())
21+
b = int(raw_input())
22+
23+
print a // b
24+
print a / b
25+
Python 3
26+
27+
a = int(input())
28+
b = int(input())
29+
30+
print(a // b)
31+
print(a / b)
32+
"""

Diff for: 1 Introduction/Say Hello, World! With Python.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
print("Hello, World!")
2+
"""
3+
Editorial by DOSHI
4+
Use print to write the resulting object to standard output.
5+
6+
Python 2
7+
8+
print "Hello, World!"
9+
Python 3
10+
11+
print("Hello, World!")
12+
"""

Diff for: 1 Introduction/Write a function.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def is_leap(year):
2+
leap = False
3+
4+
# Write your logic here
5+
if((year%400 == 0) or ( year%4 == 0 and year%100 != 0)):
6+
leap= True
7+
8+
return leap
9+
10+
"""
11+
Editorial by shashank21j
12+
Just implement a function using def and if-else logic.
13+
14+
Solutions
15+
Python 2
16+
17+
def is_leap(n):
18+
if n % 400 == 0:
19+
return True
20+
if n % 100 == 0:
21+
return False
22+
if n % 4 == 0:
23+
return True
24+
return False
25+
26+
print is_leap(input())
27+
Python 3
28+
29+
def is_leap(n):
30+
if n % 400 == 0:
31+
return True
32+
if n % 100 == 0:
33+
return False
34+
if n % 4 == 0:
35+
return True
36+
return False
37+
38+
print(is_leap(int(input())))
39+
Python 2
40+
41+
def is_leap(year):
42+
return (year % 400 == 0) or (( year % 100 != 0) and (year % 4 == 0))
43+
44+
print is_leap(input())
45+
"""

Diff for: 2 Basic Data Types/Find the Runner-Up Score!.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
arr = list( map(int, input().split()))
4+
arr.sort(reverse=True)
5+
for i in arr:
6+
if(i<arr[0]):
7+
print(i)
8+
break
9+
10+
"""
11+
Editorial by shashank21j
12+
There are many ways to solve this problem.
13+
14+
This can be solved by maintaining two variables and . Iterate through the list and find the maximum and store it. Iterate again and find the next maximum value by having an if condition that checks if it's not equal to first maximum.
15+
16+
Create a counter from the given array. Extract the keys, sort them and print the second last element.
17+
18+
Transform the list to a set and then list again, removing all the duplicates. Then sort the list and print the second last element.
19+
20+
Set by harsh_beria93
21+
Problem Setter's code:
22+
23+
Python 2
24+
25+
if __name__ == '__main__':
26+
n = int(raw_input())
27+
arr = map(int, raw_input().split())
28+
m1 = max(arr)
29+
m2 = -9999999999
30+
for i in range(n):
31+
if arr[i] != m1 and arr[i] > m2:
32+
m2 = arr[i]
33+
print m2
34+
from collections import Counter
35+
if __name__ == '__main__':
36+
n = int(raw_input())
37+
arr = Counter(map(int, raw_input().split())).keys()
38+
arr.sort()
39+
print arr[-2]
40+
from collections import Counter
41+
if __name__ == '__main__':
42+
n = int(raw_input())
43+
arr = list(set(map(int, raw_input().split())))
44+
arr.sort()
45+
print arr[-2]
46+
"""

Diff for: 2 Basic Data Types/Finding the percentage.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
student_marks = {}
4+
for _ in range(n):
5+
name, *line = input().split()
6+
scores = list(map(float, line))
7+
student_marks[name] = scores
8+
query_name = input()
9+
#print (student_marks[query_name][1])
10+
result = float(0)
11+
result = result + student_marks[query_name][0]
12+
result = result + student_marks[query_name][1]
13+
result = result + student_marks[query_name][2]
14+
result = float(result/3.00)
15+
print("{0:.2f}".format(result))
16+
17+
"""
18+
Editorial by DOSHI
19+
Use a dictionary to store the averages as values and the name as keys.
20+
21+
Tested by DOSHI
22+
Problem Tester's code:
23+
24+
d={}
25+
for i in range(int(raw_input())):
26+
line=raw_input().split()
27+
d[line[0]]=sum(map(float,line[1:]))/3
28+
29+
print '%.2f' % d[raw_input()]
30+
"""

Diff for: 2 Basic Data Types/List Comprehensions.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if __name__ == '__main__':
2+
x = int(input())
3+
y = int(input())
4+
z = int(input())
5+
n = int(input())
6+
a = []
7+
for i in range(x+1):
8+
for j in range(y+1):
9+
for k in range(z+1):
10+
if(i+j+k != n ):
11+
a.append([i,j,k])
12+
13+
print(a)
14+
15+
"""
16+
Editorial by DOSHI
17+
List comprehensions are an elegant way where lists can be built without having to use different for loops to append values one by one.
18+
19+
Solution
20+
21+
Python 2
22+
a, b, c, n = [int(raw_input()) for _ in xrange(4)]
23+
print [[x,y,z] for x in xrange(a + 1) for y in xrange(b + 1) for z in xrange(c + 1) if x + y + z != n]
24+
"""

Diff for: 2 Basic Data Types/Lists.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
if __name__ == '__main__':
2+
n = int(input())
3+
l = []
4+
for _ in range(n):
5+
s = input().split()
6+
if(s[0]=='insert'):
7+
a = int(s[1])
8+
b = int(s[2])
9+
l.insert(a, b)
10+
elif(s[0]=='print'):
11+
print(l)
12+
elif(s[0]=='remove'):
13+
a = int(s[1])
14+
l.remove(a)
15+
elif(s[0]=='append'):
16+
a = int(s[1])
17+
l.append(a)
18+
elif(s[0]=='sort'):
19+
l.sort()
20+
elif(s[0]=='pop'):
21+
l.pop()
22+
elif(s[0]=='reverse'):
23+
l.reverse()
24+
25+
"""
26+
Editorial by DOSHI
27+
We can solve this using list methods and conditionals.
28+
29+
Tested by DOSHI
30+
Problem Tester's code:
31+
32+
arr = []
33+
for i in range(int(raw_input())):
34+
s = raw_input().split()
35+
for i in range(1,len(s)):
36+
s[i] = int(s[i])
37+
38+
if s[0] == "append":
39+
arr.append(s[1])
40+
elif s[0] == "extend":
41+
arr.extend(s[1:])
42+
elif s[0] == "insert":
43+
arr.insert(s[1],s[2])
44+
elif s[0] == "remove":
45+
arr.remove(s[1])
46+
elif s[0] == "pop":
47+
arr.pop()
48+
elif s[0] == "index":
49+
print arr.index(s[1])
50+
elif s[0] == "count":
51+
print arr.count(s[1])
52+
elif s[0] == "sort":
53+
arr.sort()
54+
elif s[0] == "reverse":
55+
arr.reverse()
56+
elif s[0] == "print":
57+
print arr
58+
"""

0 commit comments

Comments
 (0)