Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4149809

Browse files
Python Program
1 parent f66e06b commit 4149809

File tree

79 files changed

+2535
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2535
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Feb 29 15:16:01 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
#
8+
#n1 = int(input())
9+
#ele1 = [int(x) for x in input().split()]
10+
#n2 = int(input())
11+
#ele2 = [int(x) for x in input().split()]
12+
13+
14+
15+
16+
def arrayIntersection(a1,a2,n1,n2):
17+
a1.sort()
18+
a2.sort()
19+
i =0
20+
j = 0
21+
while i<n1 and j<n2:
22+
if a1[i] == a2[j]:
23+
#print("earth")
24+
print(a1[i])
25+
i+=1
26+
j+=1
27+
elif a1[i]<a2[j]:
28+
i+=1
29+
#print("mars")
30+
else:
31+
#print("saturn")
32+
j+=1
33+
# elif a2[j]>a1[i]:
34+
# j+=1
35+
36+
37+
38+
n1 = 5
39+
ele1 = [2,6,2,3,2]
40+
n2 = 3
41+
ele2 = [3,2,2]
42+
43+
arrayIntersection(ele1,ele2,n1,n2)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Feb 29 13:01:46 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
n = int(input())
9+
a = [int(x) for x in input().split()]
10+
11+
for i in range(n):
12+
for j in range(n):
13+
if i!=j and a[i]==a[j]:
14+
break
15+
else:
16+
print(a[i])
17+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Mar 1 11:36:12 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
def sort0and1(n,a):
8+
i = 0
9+
j = n-1
10+
while(i<j):
11+
if a[i] == 0:
12+
i+=1
13+
14+
elif a[j] == 1:
15+
j-=1
16+
17+
elif a[i]!=0 and a[j]!=1:
18+
a[i],a[j] = a[j],a[i]
19+
i+=1
20+
j-=1
21+
22+
return a
23+
24+
n = int(input())
25+
a = [int(x) for x in input().split()]
26+
resultArray = sort0and1(n,a)
27+
28+
for data in resultArray:
29+
print(data,end = " ")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Mar 1 10:12:08 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
9+
10+
def doubletSum(n,a,num):
11+
for i in range(n):
12+
for j in range(i+1,n):
13+
if i!=j and a[i]+a[j] == num :
14+
if a[i] < a[j]:
15+
print(a[i],a[j])
16+
else:
17+
print(a[j],a[i])
18+
19+
20+
n = int(input())
21+
arr = [int(x) for x in input().split()]
22+
num = int(input())
23+
doubletSum(n,arr,num)
24+
25+
26+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Feb 29 14:38:26 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
def findDuplicate(a,n):
9+
for i in range(n):
10+
for j in range(n):
11+
if i!=j and a[i]==a[j]:
12+
return a[i]
13+
14+
15+
16+
n = int(input())
17+
a = [int(x) for x in input().split()]
18+
result = findDuplicate(a,n)
19+
print(result)
20+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Mar 1 10:45:33 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
def doubletSum(n,a,num):
9+
for i in range(n):
10+
for j in range(i+1,n):
11+
for k in range(j+1,n):
12+
13+
if i!=j!=k and a[i]+a[j]+a[k] == num :
14+
15+
16+
if a[i] > a[j] and a[i] > a[k] and a[j]>a[k]:
17+
print(a[k],a[j],a[i])
18+
19+
elif a[i] > a[j] and a[i] > a[k] and a[j]<a[k]:
20+
print(a[j],a[k],a[i])
21+
22+
elif a[j]>a[i] and a[j]>a[k] and a[k]>a[i] :
23+
print(a[i],a[k],a[j])
24+
25+
elif a[j]>a[i] and a[j]>a[k] and a[k]<a[i] :
26+
print(a[k],a[i],a[j])
27+
28+
elif a[k]>a[i] and a[k]>a[j] and a[i]>a[j]:
29+
print(a[j],a[i],a[k])
30+
31+
elif a[k]>a[i] and a[k]>a[j] and a[i]<a[j]:
32+
print(a[i],a[j],a[k])
33+
34+
35+
n = int(input())
36+
arr = [int(x) for x in input().split()]
37+
num = int(input())
38+
doubletSum(n,arr,num)
39+
40+
#70
41+
#9 5 7 27 22 21 2 7 10 12 3 26 10 19 18 24 9 30 12 18 12 13 11 18 3 3 12 22 29 19 11 21 29 3 1 9 5 26 29 23 30 27 8 11 12 20 5 28 5 3 11 22 18 24 12 29 25 17 29 18 20 18 25 27 10 5 30 29 5 14
42+
#66

‎Arrays and List/lectures/Array Sum.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def listSum(n,elements):
2+
sum_ = 0
3+
for data in elements:
4+
sum_ = sum_ + data
5+
6+
return sum_
7+
8+
lenghtOfList = int(input())
9+
#elements = list(map(int,input().split(" ")))
10+
elements = [int(x) for x in input().split()]
11+
result = listSum(lenghtOfList,elements)
12+
print(result)
13+
14+
#data = []
15+
#for i in input().split():
16+
# data.append(int(i))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Feb 29 12:36:33 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
def swapAlternate(elem,n):
8+
i=0
9+
while i < n-1:
10+
elem[i],elem[i+1] = elem[i+1],elem[i]
11+
i+=2
12+
return elem
13+
14+
n = int(input())
15+
elem =[int(x) for x in input().split()]
16+
result = swapAlternate(elem,n)
17+
for i in result:
18+
print(i,end= " ")

‎Conditionals and loops/Calculator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Feb 16 19:46:20 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
flag = True
9+
while flag:
10+
choice = int(input())
11+
if choice < 6:
12+
n1 = int(input())
13+
n2 = int(input())
14+
15+
if choice == 1:
16+
print(n1+n2)
17+
elif choice == 2:
18+
print(n1-n2)
19+
elif choice == 3:
20+
print(n1*n2)
21+
elif choice == 4:
22+
print(n1//n2)
23+
elif choice == 5:
24+
print(n1%n2)
25+
elif choice == 6:
26+
flag = False
27+
elif choice == 6:
28+
flag = False
29+
30+
else:
31+
print("Invalid Operation")
32+
33+
34+
35+

‎Conditionals and loops/Check number.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Feb 16 18:03:26 2020
4+
5+
@author: cheerag.verma
6+
"""
7+
8+
number = int(input())
9+
10+
if number > 0:
11+
print("Positive")
12+
elif number < 0:
13+
print("Negative")
14+
else:
15+
print("Zero")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /