0% found this document useful (0 votes)
3 views

CSC project

The document contains Python programming exercises that demonstrate various concepts such as calculating the factorial of a number, user authentication with default arguments, and using variable-length arguments to compute the sum and product of the first ten numbers. It also includes a file handling exercise where a user can write text to a file named 'intro.txt'. Each section provides code snippets and sample outputs for clarity.

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)
3 views

CSC project

The document contains Python programming exercises that demonstrate various concepts such as calculating the factorial of a number, user authentication with default arguments, and using variable-length arguments to compute the sum and product of the first ten numbers. It also includes a file handling exercise where a user can write text to a file named 'intro.txt'. Each section provides code snippets and sample outputs for clarity.

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/ 3

1.

Working with function


1.1 Question 1.
Write a python using a function to print factorial of a number
‘n’.
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)

Enter a number to find factorial: 3


Factorial of 3 is 6
1.2 Question 2.
Write a python program to accept username “Admin” as dfault
argument and password 123 entered by user to allow login into
the system.
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)
Enter the password :123
You have logged into system
1.3 Question 3:
Write a python program to demonstrate e concept of variable
length argument to calculate product and power of the first 10
numbers.
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

2. FiLE HANDLING

2.1 Question 4:
Create a text file “intro.txt” in python and ask the user to write
a single lie text by user input .
def program4():
f = open("intro.txt","w")
text = input("Enter the text:")
f.write(text)
f.close()

program4()

OUTPUT:
Enter the text: Python is a programming language.
Question 5

You might also like