Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21 Days Programming Solutions #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions Software/MyRepoPy/Day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import math
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))
print("The quadratic equation is: {}X2 + {}X + {} = 0".format(a,b,c))
d = b**2 - 4*a*c
print('The value of d is: ',d)
if d>0:

r1 = (-b + math.sqrt(d))/(2 * a)
r2 = (-b - math.sqrt(d))/(2 * a)
print("Roots are real and unequal ",r1,r2)
elif d==0:

r1 = -b/(2*a)
print("Roots are real and same ",r1)
else:

A = (-b/(2*a))
s = (4*a*c - b**2)
B = (math.sqrt(s))/(2 * a)

print("Roots are complex and imaginary {} + {}i and {} - {}i".format(A,B,A,B))

24 changes: 24 additions & 0 deletions Software/MyRepoPy/Day1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import math
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))
print("The quadratic equation is: {}X2 + {}X + {} = 0".format(a,b,c))
d = b**2 - 4*a*c
print('The value of d is: ',d)
if d>0:

r1 = (-b + math.sqrt(d))/(2 * a)
r2 = (-b - math.sqrt(d))/(2 * a)
print("Roots are real and unequal ",r1,r2)
elif d==0:

r1 = -b/(2*a)
print("Roots are real and same ",r1)
else:

A = (-b/(2*a))
s = (4*a*c - b**2)
B = (math.sqrt(s))/(2 * a)

print("Roots are complex and imaginary {} + {}i and {} - {}i".format(A,B,A,B))

13 changes: 13 additions & 0 deletions Software/MyRepoPy/Day2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
n = int(input("Enter number of rows: "))
for i in range(n):
print(' '*(2*(n-1-i)),end=' ')
r = (2*i)+1
for j in range(r):
## make the 1st iteration for range/2
if (j <= (int(r/2))):
print(chr(65+j),end=' ')
m = (65+j)
## return back from that range/2 to 0
else:
print((chr(m - 1 - j + (int(r/2)+1))),end=' ')
print()
13 changes: 13 additions & 0 deletions Software/MyRepoPy/Day2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
n = int(input("Enter number of rows: "))
for i in range(n):
print(' '*(2*(n-1-i)),end=' ')
r = (2*i)+1
for j in range(r):
## make the 1st iteration for range/2
if (j <= (int(r/2))):
print(chr(65+j),end=' ')
m = (65+j)
## return back from that range/2 to 0
else:
print((chr(m - 1 - j + (int(r/2)+1))),end=' ')
print()
11 changes: 11 additions & 0 deletions Software/MyRepoPy/Day3 (2).txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import math
m = int(input("Enter the starting number of GP Series: "))
n = int(input("Enter the number of terms for the GP Series: "))
r = int(input("Enter the common ratio of G.P. Series: "))
sum = 0
for i in range(n):
print(m * (pow(r,i)))

print(' ')
sum = m *((pow(r,n))-1/(r-1))
print("SUM ={}".format(int(sum)))
12 changes: 12 additions & 0 deletions Software/MyRepoPy/Day3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import math
m = int(input("Enter the starting number of GP Series: "))
n = int(input("Enter the number of terms for the GP Series: "))
r = int(input("Enter the common ratio of G.P. Series: "))
sum = 0
for i in range(n):
print(m * (pow(r,i)))

print(' ')
sum = m *((pow(r,n))-1/(r-1))
print("SUM ={}".format(int(sum)))
ch = input("Enter any key to exit")
6 changes: 6 additions & 0 deletions Software/MyRepoPy/Day_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
n = list(input("Enter a list of numbers here: "))
temp = n[0]
n[0] = n[-1]
n[-1] = temp
print(n)
input("Enter any key to exit")
10 changes: 10 additions & 0 deletions Software/MyRepoPy/Day_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
str1 = input("Enter time in this format HH:MM:SS AM/PM ")
if str1[-2:] == 'AM' and str1[:2] == "12":
print ("00" + str1[2:-2])
elif str1[-2:] == "AM":
print (str1[:-2])
elif str1[-2:] == "PM" and str1[:2] == "12":
print (str1[:-2])
else:
print (str(int(str1[:2]) + 12) + str1[2:8])
input("Enter any key to exit")
6 changes: 6 additions & 0 deletions Software/MyRepoPy/Day_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
x = int(input("Enter an integer: "))
if x % 11 == 0:
print("Yes")
else:
print("No")
input("Enter any key to exit")
19 changes: 19 additions & 0 deletions Software/MyRepoPy/Day_13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def prime(n):
bru = 0
for i in range (2,n):
if n % i == 0:
bru = 1
break
if bru == 0 or n == 1:
return 1
else:
return 0
def primebig(k):
for i in range(1,k):
if k % i == 0:
if prime(i):
t = i
return t

k = int(input("Enter a number from 1 to 1015 to get its largest prime factor:"))
print (primebig(k))
9 changes: 9 additions & 0 deletions Software/MyRepoPy/Day_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
str1 = input("Enter any String: ")
str2 = input("Enter the substring you want to replace: ")
str3 = input("Enter the string you want to replace it with: ")
s = str1.replace(str2,str3)
print("The original string is: ",str1)
print("The substring you want to replace: ",str2)
print("The string you want to use instead: ",str3)
print(s)
input("Enter any key")
14 changes: 14 additions & 0 deletions Software/MyRepoPy/Day_15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mc = input("Enter your Secret Code")
c=0
for i in mc:
if i == " ":
print (chr(ord(i)),end = "" )
c=0
elif c%2 == 0:
print (chr(ord(i)-1),end = "" )
c+=1
elif c%2 == 1:
print (chr(ord(i)+1),end = "" )
c+=1
print("")
m = input("Enter any key")
13 changes: 13 additions & 0 deletions Software/MyRepoPy/Day_17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def fibonacci(a,b,n):
if n>0:
print (a+b)
fibonacci(b,a+b,n-1)

a=int(input())
b=int(input())
n=int(input())
print("Fibonacci Series")
print (a)
print (b)
fibonacci(a,b,n)
h=input("Enter any key")
18 changes: 18 additions & 0 deletions Software/MyRepoPy/Day_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def prime(x):
z=0
if x>1:
for i in range(2,x):
if x%i == 0:
return 0
z=1
if z==0:
return 1

a = int (input ("Enter a beginning number"))
b = int (input ("Enter a ending number"))

for i in range(a,b+1):
if prime(i):
print ("{} ".format(i))

ch = input("Press any key to exit")
9 changes: 9 additions & 0 deletions Software/MyRepoPy/Day_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
x = int(input("Enter a number: "))
s = []
while x > 0:
i = x % 10
s.append(i)
x = x//10
y = s.count(i)

print("The frequency of {} is = {}".format(i,y))
3 changes: 3 additions & 0 deletions Software/MyRepoPy/Day_7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def check_pal(x):
x = x.replace(' ','')
return x == x[::-1]
8 changes: 8 additions & 0 deletions Software/MyRepoPy/Day_8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n = int(input("Enter the number of scores: "))
A = []
for i in range(1,n+1):
A.append(i)
A.sort()
print(A)
print("The runner-up score is: ",A[n-2])
input("Enter any key to exit")
10 changes: 10 additions & 0 deletions Software/MyRepoPy/Day_9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
s = int(input("Input any number of your Choice: "))
sum = 0
for num in range(1,s+1):
x = s%num
if x == 0:

if num % 2 != 0:
sum += num
print(sum)
ch = input("Enter any key to exit")
1 change: 1 addition & 0 deletions Software/MyRepoPy/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21 days programming challenge solution.