Skip to content

Commit 5e4e5de

Browse files
committed
projects
1 parent e5d4778 commit 5e4e5de

13 files changed

Lines changed: 768 additions & 0 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Mixed = input("Enter mixed letters and numbers: ")
2+
3+
def extract_from(x):
4+
if len(Mixed)==0:
5+
print("Nothing Entered")
6+
else:
7+
try:
8+
letters = [letter for letter in x if letter.isalpha()]
9+
if len(letters)!=0:
10+
print(f"List of all the letters is: {letters}")
11+
12+
numbers = [number for number in x if number.isdigit()]
13+
if len(numbers)!=0:
14+
print(f"List of all the numbers is: {numbers}")
15+
16+
others = [other for other in x if other.isdigit()==False and other.isalpha()==False]
17+
if len(others)!=0:
18+
print(f"Other Special characters is: {others}")
19+
except Exception as e:
20+
print(f"ERROR: {e}")
21+
22+
extract_from(Mixed)
23+
print("\n-----*---*-----\n")
24+
#----- Further it can be modified to give unique letters, numbers or special characters or to give how many numbers, letters and special characters are present ----
25+
#--------- EXAMPLE ----
26+
def count_char(x):
27+
if len(x)==0:
28+
return
29+
else:
30+
try:
31+
letters = [letter for letter in x if letter.isalpha()]
32+
if len(letters)!=0:
33+
print(f"No of unique letters: {len(set(letters))}")
34+
35+
numbers = [number for number in x if number.isdigit()]
36+
if len(numbers)!=0:
37+
print(f"No of unique digits: {len(set(numbers))}")
38+
39+
others = [other for other in x if other.isdigit()==False and other.isalpha()==False]
40+
if len(others)!=0:
41+
print(f"No of unique Special character: {len(set(others))}")
42+
except Exception as e:
43+
print(f"ERROR: {e}")
44+
45+
count_char(Mixed)

projects/Fibonacci.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def fibonacci(n):
2+
sequence = [0,1]
3+
4+
for _ in range(n-2):
5+
sequence.append(sequence[-2] + sequence [-1])
6+
return sequence
7+
8+
try:
9+
n = int(input("Upto how many digits you want the Fibonacci sequence: "))
10+
if n<=0:
11+
print("Enter a natural number.")
12+
if n==1:
13+
print("Fibonacci series of 1 digit is [0]")
14+
if n==2:
15+
print("Fibonacci series of 2 digit is [0,1]")
16+
if n>2:
17+
print(f"Fibonacci series of {n} digit is:\n{fibonacci(n)}")
18+
except Exception as e:
19+
print(f"ERROR: {e}")

projects/Permutation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import math
2+
print("Permutations of 'n' distinct objects taken 'r' at a time is given by:\nnPr = n!/(n-r)!, where \"!\" denotes the factorial.\n")
3+
4+
try:
5+
n = int(input("Enter the value of n (n>0): "))
6+
r = int(input("Enter the value of r (0<=r<=n): "))
7+
if n<=0 or r<0:
8+
print("'n' should be greater than 0 and 'r' must be >=0")
9+
elif r>n:
10+
print("'r' can't be greater than 'n'")
11+
else:
12+
ans = (math.factorial(n))//(math.factorial(n-r))
13+
print(f"\nPermutation of {n} distinct objects taken {r} at a time is: {ans}")
14+
15+
except Exception as e:
16+
print(f"ERROR: {e}")

projects/QR_generator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import qrcode
2+
from qrcode.constants import ERROR_CORRECT_H
3+
4+
5+
data = "add any text, or link here"
6+
7+
8+
qr = qrcode.QRCode(
9+
version=1,
10+
error_correction=ERROR_CORRECT_H,
11+
box_size=10,
12+
border=4,
13+
)
14+
15+
qr.add_data(data)
16+
qr.make(fit=True)
17+
18+
img = qr.make_image(fill_color="black", back_color="white")
19+
img.save("qrcode.png")
20+
print("QR code saved as qrcode.png")
21+
22+
23+
print("\nSCAN ON YOUR OWN RISK:\n")
24+
25+
qr.print_ascii(invert=True)

projects/Solving_quadratic.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import math
2+
print("General form of quadratic is: ax^2 + bx + c, where (a!=0).")
3+
try:
4+
a = float(input("Enter the value for a: "))
5+
if a == 0:
6+
print("a can't be equals to zero.")
7+
else:
8+
b = float(input("Enter the value for b: "))
9+
c = float(input("Enter the value for c: "))
10+
if c == 0:
11+
print(f"The quadratic is: {a}{'+' if b>0 else '-' } {abs(b)}x")
12+
elif b==0:
13+
print(f"The quadratic is: {a}{'+' if c>0 else '-' } {abs(c)}")
14+
else:
15+
print(f"The quadratic is: {a}{'+' if b>0 else '-' } {abs(b)}x {'+' if c>0 else '-' } {abs(c)}")
16+
17+
d = b**2 - 4*a*c
18+
19+
if d<0:
20+
print("This quadratic have complex roots.")
21+
if b==0:
22+
imag = round(((math.sqrt(-d))/(2*a)), 2)
23+
root1 = (f"i{imag}")
24+
root2 = (f"-i{imag}")
25+
print(f"The roots of given quadratic are \'{root1}\' and \'{root2}\'.")
26+
else:
27+
real = round((-b)/(2*a), 2)
28+
imag = round(((math.sqrt(-d))/(2*a)), 2)
29+
root1 = (f"{real} + i{imag}")
30+
root2 = (f"{real} - i{imag}")
31+
print(f"The roots of given quadratic are \'{root1}\' and \'{root2}\'.")
32+
elif d == 0:
33+
print("This quadratic have equal roots.")
34+
print(f"Which is \'{round((-b/(2*a)), 2)}\'.")
35+
36+
else:
37+
print("This quadratic have two real and distinct roots.")
38+
root1 = round((-b + math.sqrt(d))/(2*a), 2)
39+
root2 = round((-b - math.sqrt(d))/(2*a), 2)
40+
print(f"Which are \'{root1}\' and \'{root2}\'.")
41+
except Exception as e:
42+
print(f"ERROR: {e}")

0 commit comments

Comments
 (0)