Skip to content

Commit 3987dca

Browse files
Merge pull request Devs-Dungeon#2 from kishanrajput23/main
Added 100 Python Challenges with complete solutions
2 parents cd9b67a + b788985 commit 3987dca

File tree

111 files changed

+1947
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1947
-1
lines changed

02-How to Contribute to this Repo/CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
This is a list showing the GitHub usernames of all who have contributed to this open-source project! **Make sure to add yourself and submit a pull request if you've contributed.**
1010

1111
- [@Neklaustares-tPtwP](https://github.com/Neklaustares-tPtwP)
12-
-
12+
- [@kishanrajput23](https://github.com/kishanrajput23)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
1. Write a function that accepts three variables a,b,c and returns the sum of these variables, if the
3+
values are equal then return two times their sum.
4+
"""
5+
6+
7+
def sum_num(a,b,c):
8+
if a == b == c:
9+
return 2 * (a+b+c)
10+
else:
11+
return (a+b+c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
3+
Write a function that accepts a random number and checks if number is equal to the sum of its positive divisors, except itself.
4+
5+
Example:
6+
7+
Input num = 28
8+
9+
Expected output = True
10+
11+
"""
12+
13+
14+
def sum_pos_divisor(num):
15+
sum = 0
16+
for i in range(1, num):
17+
if num % i == 0:
18+
sum += i
19+
else:
20+
continue
21+
if sum == num:
22+
return True
23+
else:
24+
return False
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Write a function that accepts two arguments year and month, and then checks if the month has Friday the 13th.
3+
4+
Example:
5+
6+
year = 2020, month = 3
7+
8+
Expected output = True
9+
"""
10+
11+
12+
from datetime import datetime
13+
14+
def check_friday_13(yr, mon):
15+
user_date = datetime(yr, mon, 13)
16+
if user_date.strftime("%A") == "Friday":
17+
return datetime(yr, mon, 13), True
18+
else:
19+
return datetime(yr, mon, 13), False
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Given two numbers a and b.
3+
Create a function that returns the next number greater than a and b and divisible by b. (a>b)
4+
5+
Example:
6+
7+
a = 25, b = 5
8+
9+
Expected output = 30
10+
"""
11+
12+
def check_division(a,b):
13+
if a > b:
14+
for num in range(1, a+b+1):
15+
if num % b == 0 and num > a and num > b:
16+
return num
17+
else:
18+
continue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Write a function that chooses a random number 'n' from 1 and 5000 (inclusive) and then calculates the length of this number 'n'.
3+
Do not use the built-in function 'len' to calculate the length.
4+
5+
Example:
6+
7+
n =1000
8+
9+
length = 4
10+
"""
11+
12+
import random
13+
14+
def calculate_length():
15+
n = random.randint(1,5000)
16+
count = 0
17+
for i in str(n):
18+
count += 1
19+
20+
return (n, count)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Write a Python function that accepts three Boolean variables - x, y, and z.
3+
The function should return True if at least two out of the three variables are True.
4+
5+
Example :
6+
7+
x = True, y = False, z = True
8+
9+
Expected output = True
10+
"""
11+
12+
def booleans(x,y,z):
13+
if x == "True" and y == "True" and z == "False":
14+
result = True
15+
return (x, y, z, result)
16+
elif x == "True" and y == "False" and z == "True":
17+
result = True
18+
return (x, y, z, result)
19+
elif x == "False" and y == "True" and z == "True":
20+
result = True
21+
return (x, y, z, result)
22+
elif x == "False" and y == "False" and z == "True":
23+
result = False
24+
return (x, y, z, result)
25+
elif x == "False" and y == "True" and z == "False":
26+
result = False
27+
return (x, y, z, result)
28+
elif x == "True" and y == "False" and z == "False":
29+
result = False
30+
return (x, y, z, result)
31+
elif x == "True" and y == "True" and z == "True":
32+
result = True
33+
return (x, y, z, result)
34+
else:
35+
result = False
36+
return (x, y, z, result)
37+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Write a Python function that randomly chooses any number from 1 to 10 (inclusive)
3+
and then calculates the factorial of the number.
4+
5+
Example :
6+
7+
num = 5
8+
9+
factorial = 5*4*3*2*1 = 120
10+
"""
11+
12+
import random
13+
14+
def factorial():
15+
k = random.randint(1,10)
16+
num = 1
17+
for i in range(1, k+1):
18+
num *= i
19+
return (k, num)
20+
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Write a Python function that takes a division equation d and checks
3+
if it returns a whole number without decimals after dividing.
4+
5+
Examples:
6+
7+
check_division(4/2) ➞ True
8+
9+
check_division(25/2) ➞ False
10+
"""
11+
12+
def check_division(num):
13+
if num % 2 == 0:
14+
return num, True
15+
else:
16+
return num, False
17+
18+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Write a function that accepts a number and returns True if the number is a prime number else returns False.
3+
A prime number is an integer which cannot be divided evenly by any integer except 1 and itself.
4+
You may assume that n is a non-negative integer.
5+
6+
7+
"""
8+
9+
def prime_num(num):
10+
if num > 1:
11+
flag = False
12+
for i in range(2, num):
13+
if num % i == 0:
14+
flag = True
15+
break
16+
if flag:
17+
return False
18+
else:
19+
return True
20+
21+
22+
23+

0 commit comments

Comments
 (0)