Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions 1_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def divisible(num,div):
if(num%div==0):
return 1
else:
return 0

sum=0;
for i in range(1,500):
if divisible(i,5) and not divisible(i,7):
sum+=i

print("sum of numbers less than 500 which are divisible by 5 and not divisible by 7 is: {}".format(sum))
3 changes: 3 additions & 0 deletions 2_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
l,b,h=6,8,10
l,b,h=l*1.15,b*1.15,h*1.15
print("required area is: {:.4f}".format(2*(l*b+b*h+h*l)))
9 changes: 9 additions & 0 deletions 3_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
list1=["Ron","Hermione","Harry","Professor","Dobby","List Items 2","The House Elf","Potter","Granger","Lockhart","Weasley"]
list2=["Potter","Fred","Greg","George","Voldemort","Sirius","Dumbledore"]
temp=""
l=len(list1)
for i in range(0,l-1):
for j in range(0,l-i-1):
if list1[j]>list1[j+1]:
list1[j],list1[j+1]=list1[j+1],list1[j]
print(list1+list2)
7 changes: 7 additions & 0 deletions 4_pythagorean_triplet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for a in range(1, 1000):
for b in range(a+1, 1000):
c = 1000-(a+b)
if (a**2)+(b**2)==(c**2):
if a+b+c==1000:
print(a*b*c)
break
10 changes: 10 additions & 0 deletions 5_lcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def gcd(a,b):
while b:
a,b=b,a%b
return a
def lcm(a,b):
return (a*b)//gcd(a,b)
x=1
for i in range(2,21):
x=lcm(x,i)
print(x)
11 changes: 11 additions & 0 deletions 6_prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def prime(n):
for i in range(2,n//2+1):
if n%i==0:
return -1
return 1
x=0
print("prime numbers between 1 and 99999:")
for i in range(1,99999):
x=prime(i)
if(x==1):
print(i)
6 changes: 6 additions & 0 deletions 7_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
s1=input("Enter a string: ")
s2=s1[::-1]
if s1==s2:
print("{} is palindrome".format(s1))
else:
print("{} is not a palindrome".format(s1))