0% found this document useful (0 votes)
47 views2 pages

Document 3

The document contains three Python programs: the first calculates the factorial of a user-provided number, the second allows a user to log in with a default username and a password, and the third demonstrates variable-length arguments to compute the sum and product of the first ten numbers. Each program includes sample code and expected output for clarity. The examples illustrate basic Python functions and user input handling.

Uploaded by

Anwesha Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Document 3

The document contains three Python programs: the first calculates the factorial of a user-provided number, the second allows a user to log in with a default username and a password, and the third demonstrates variable-length arguments to compute the sum and product of the first ten numbers. Each program includes sample code and expected output for clarity. The examples illustrate basic Python functions and user input handling.

Uploaded by

Anwesha Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1. Write a python function factorial() to find the factorial of a number ‘n’.

Take the value from the user.

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.

Q2. Write a python program to accept username “Admin” as default argument


and password 123 entered by the user to allow login into the system.

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!!!!!!

Q3. Write a python program to demonstrate the concept of variable length


argument to calculate sum and product of the first 10 numbers.

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

You might also like