Movatterモバイル変換


[0]ホーム

URL:


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

Commita444d31

Browse files
authored
Merge pull requestpowerexploit#2 from sachith-1/master
Create Factorial.py
2 parents166f189 +f491971 commita444d31

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+
ifnum<0:
13+
print("Sorry, factorial does not exist for negative numbers")
14+
elifnum==0:
15+
print("The factorial of 0 is 1")
16+
else:
17+
foriinrange(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+
defpypart(n):
3+
4+
# outer loop to handle number of rows
5+
# n in this case
6+
foriinrange(0,n):
7+
8+
# inner loop to handle number of columns
9+
# values changing acc. to outer loop
10+
forjinrange(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)

[8]ページ先頭

©2009-2025 Movatter.jp