Skip to content

Commit a444d31

Browse files
authored
Merge pull request powerexploit#2 from sachith-1/master
Create Factorial.py
2 parents 166f189 + f491971 commit a444d31

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Scripts/Factorial.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Python program to find the factorial of a number provided by the user.
2+
3+
# change the value for a different result
4+
num = 7
5+
6+
# uncomment to take input from the user
7+
#num = int(input("Enter a number: "))
8+
9+
factorial = 1
10+
11+
# check if the number is negative, positive or zero
12+
if num < 0:
13+
print("Sorry, factorial does not exist for negative numbers")
14+
elif num == 0:
15+
print("The factorial of 0 is 1")
16+
else:
17+
for i in range(1,num + 1):
18+
factorial = factorial*i
19+
print("The factorial of",num,"is",factorial)

Scripts/starpattern.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Function to demonstrate printing pattern
2+
def pypart(n):
3+
4+
# outer loop to handle number of rows
5+
# n in this case
6+
for i in range(0, n):
7+
8+
# inner loop to handle number of columns
9+
# values changing acc. to outer loop
10+
for j in range(0, i+1):
11+
12+
# printing stars
13+
print("* ",end="")
14+
15+
# ending line after each row
16+
print("\r")
17+
18+
# Driver Code
19+
n = 5
20+
pypart(n)

0 commit comments

Comments
 (0)