Skip to content

Commit fa01417

Browse files
Some more Files Added In Python Codes
1 parent be77b44 commit fa01417

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Python Basic/Regex.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import re
2+
3+
#Check if the string starts with "The" and ends with "Spain":
4+
5+
txt = "The rain in Spain"
6+
x = re.search("^The.*Spain$", txt)
7+
8+
if (x):
9+
print("YES! We have a match!")
10+
else:
11+
print("No match")
12+
'''
13+
findall :Returns a list containing all matches
14+
search :Returns a Match object if there is a match anywhere in the string
15+
split :Returns a list where the string has been split at each match
16+
sub :Replaces one or many matches with a string
17+
'''

Quardtic-Equation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""" ax2 + bx + c = 0, where
2+
a, b and c are real numbers and
3+
a ≠ 0 """
4+
import cmath
5+
def quardtic(a,b,c): #ax2 + bx + c = 0
6+
d = (b**2) -(4*a*c)
7+
sol1 = (-b -cmath.sqrt(d))/(2*a)
8+
sol2 = (-b +cmath.sqrt(d))/(2*a)
9+
return sol1,sol2
10+
11+
a, b, c=1, 5, 6
12+
answer = quardtic(a,b,c)
13+
print(answer)

hangman.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import random
2+
3+
num_attempt = 6
4+
bag_of_words = ["book", "Table", "Movie"]
5+
6+
answer = random.choice(bag_of_words)
7+
print(a)

sum_by_recursion.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def recur_sum(n):
2+
if n <= 1:
3+
return n
4+
else:
5+
return n + recur_sum (n-1)
6+
n=10
7+
ans= recur_sum(n)
8+
print(ans)

0 commit comments

Comments
 (0)