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 cfe8465

Browse files
Done with 70 python practice questions.
1 parent b33d9aa commit cfe8465

5 files changed

+65
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def Reverse(s, n):
2+
if n == 0:
3+
print(s[0])
4+
else:
5+
print(s[n], end='')
6+
Reverse(s, n - 1)
7+
8+
s = input("Enter String to find its reverse: ")
9+
Reverse(s, len(s) - 1)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def findBasetoThePower(x, y):
2+
if y == 0:
3+
return 1
4+
else:
5+
return (x * findBasetoThePower(x, y - 1))
6+
7+
x = int(input('Enter base: '))
8+
y = int(input("Enter exponent: "))
9+
result = findBasetoThePower(x, y)
10+
print(f"{x} to the power {y} is {result}.")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
factorial, in mathematics, the product of all positive integers less than or equal to a given positive
3+
integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!,
4+
meaning 1 x 2 x 3 x 4 x 5 x 6 x 7. Factorial zero is defined as equal to 1.
5+
'''
6+
7+
def Factorial(no):
8+
if no == 1:
9+
return 1
10+
else:
11+
return (no * Factorial(no - 1))
12+
13+
14+
no = int(input("Enter number to find its factorial: "))
15+
factorial = Factorial(no)
16+
print(f"Factorial of {no} is {factorial}.")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
What is GCD ?
3+
4+
The greatest common divisor (GCD), also called the greatest common factor, of two numbers is the largest
5+
number that divides them both. For instance, the greatest common factor of 20 and 15 is 5,since 5 divides
6+
both 20 and 15 and no larger number has this property.
7+
8+
'''
9+
10+
def GCD(no1, no2):
11+
if no2 == 0:
12+
return no1
13+
else:
14+
return (GCD(no2, no1 % no2))
15+
16+
17+
no1 = int(input("Enter 1st no: "))
18+
no2 = int(input("Enter 2nd no: "))
19+
gcd = GCD(no1, no2)
20+
print(f"GCD of {no1} and {no2} is {gcd}.")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def Fibonacci(i):
2+
if (i == 1):
3+
return 0 # In fibonacci series first term is always 0
4+
elif (i == 2):
5+
return 1
6+
return (Fibonacci(i - 1) + Fibonacci(i - 2))
7+
8+
no = int(input("Enter number upto which you want to print Fibonacci Series: "))
9+
for i in range(1, no + 1):
10+
print(Fibonacci(i), end=" ")

0 commit comments

Comments
(0)

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