Skip to content

Add Python example script demonstrating factorial and greeting #98356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions python_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def greet_user(name):
print(f"Hello, {name}! Welcome to First Contributions.")

def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n-1)

def print_factorials_up_to(n):
print(f"Factorials from 0 to {n}:")
for i in range(n+1):
print(f"{i}! = {factorial(i)}")

if __name__ == "__main__":
user_name = input("Enter your name: ")
greet_user(user_name)

max_num = int(input("Enter a number to calculate factorials up to: "))
print_factorials_up_to(max_num)