Document 3
Document 3
Program Code
def factorial(n):
fact=1
for i in range(1, n+1):
fact*=i
print(f"Factorial of {n} is {fact}.")
num = int(input("Enter a number to find factorial: "))
factorial(num)
Output
Enter a number to find factorial: 4
Factorial of 4 is 24.
Program Code
def user_pass(password, username = "Admin"):
if password == "123":
print("You have logged into system.")
else:
print("Password is incorrect!!!!!!")
password = input("Enter the password: ")
user_pass(password)
Output
Test Case 1:
Enter the password: 123
You have logged into system.
Test Case 2:
Enter the password: 2gh
Password is incorrect!!!!!!
Program Code
def sum10(*n):
total = 0
for i in n:
total = total + i
print("Sum of first 10 numbers = ", total)
sum10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
def product10(*n):
pr = 1
for i in n:
pr = pr * i
print("Product of first 10 numbers = ", pr)
product10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Output
Sum of first 10 numbers = 55
Product of first 10 numbers = 3628800