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

Commitedcdffd

Browse files
authored
Create Factorial.py
1 parenta3211f8 commitedcdffd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-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)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp