KEMBAR78
Program | PDF
0% found this document useful (0 votes)
11 views5 pages

Program

The document contains several practical programming exercises in Python, including generating random numbers within a range, checking if two strings are of the same length, finding the maximum and minimum of four numbers, calculating the sum and product of the first ten numbers using variable-length arguments, and implementing a simple login system with a default username. Each exercise includes a function definition and example output. The exercises are designed to demonstrate various programming concepts and functionalities in Python.

Uploaded by

cshekhar60836
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)
11 views5 pages

Program

The document contains several practical programming exercises in Python, including generating random numbers within a range, checking if two strings are of the same length, finding the maximum and minimum of four numbers, calculating the sum and product of the first ten numbers using variable-length arguments, and implementing a simple login system with a default username. Each exercise includes a function definition and example output. The exercises are designed to demonstrate various programming concepts and functionalities in Python.

Uploaded by

cshekhar60836
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

Practical –XI

Write a function that receives two numbers and generates a random number
from that range. Using function the main should be able to print three
numbers randomly.

import random

def random_num(x,y):

return random.randint(x,y)

n1=int(input("Enter the first number:"))

n2=int(input("Enter the second number:"))

print("Random No.1:",random_num(n1,n2))

print("Random No.2:",random_num(n1,n2))

print("Random No.3:",random_num(n1,n2))

Output-
Practical –XII
Write a function that receives two string arguments and checks whether they
are same-length strings. (Returns True in this case otherwise False).

def samelength(txt1,txt2):

if len(txt1)==len(txt2):

return True

else:

return False

text1=input("Enter the text1:")

text2=input("Enter the text2:")

print("The string is same length?",samelength(text1,text2))

Output-

OR
Practical –XIII
Write a python program to find maximum and minimum numbers among
given 4 numbers.

def find_max():

l=[]

max1=0

for i in range(4):

n=int(input("Enter number into list:"))

l.append(n)

print("The list is:",l)

for i in l:

if i>max1:

max1=i

print("Max:",max1)

find_max()

Output-
Practical –XIV
Write a python program to demonstrate the concept of variable length
argument to calculate sum and product 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-
Practical –XV
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)

Output-

OR

You might also like