0% found this document useful (0 votes)
30 views5 pages

Practical File 2024-25 First Five Program

Uploaded by

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

Practical File 2024-25 First Five Program

Uploaded by

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

1.

Write a python program using a function to print factorial number


series from n to m numbers.
def facto():

n=int(input("Enter the number:"))

f=1

for i in range(1,n+1):

f*=i

print("Factorial of ",n, "is: ",f, end=" ")

facto()

2. Write a python program to accept username "Admin" as default


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)
3. Write a python program to demonstrate the 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)
4. Write a Python program to accept a list as a function parameter and

raise the IndexError exception.

Solution:

#Program to print appropriate weeks from entered numbers and display

error message through exception handling

def raise_index_error(lst):

try:

idx=int(input("Enter list index to access the value"))

print(lst[idx])

except IndexError:

print("Index not found in the list")

def main():

l=eval(input("Enter the list:"))

raise_index_error(l)

main()

Output:
5. Write a program to accept the number of days and display appropriate

weeks in an integer. Display an appropriate error message through

multiple exception handling including the finally clause.

Solution:

#Program to print appropriate weeks from entered numbers and display


error message through exception handling
def weeks_compute(days):
if days>=7:
return int(days/7)
else:
print("Days must be 7 or more than 7")
return 0
def except_weeks():
try:
days=int(input("Enter no. of days:"))
weeks=weeks_compute(days)
print("Number of weeks from entered days are:",weeks)
except ValueError:
print("Enter integers only")
except ZeroDivisionError:
print("Number days should not be zero")
else:
print("Great... You have done it...")
finally:
print("Thank you for using this program")

You might also like