Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views3 pages

PWP PR 11

The document contains a series of Python programming exercises with solutions. It includes functions for comparing lists, converting tuples to dictionaries, validating student names, counting character types in a string, and checking for prime numbers. Each exercise is accompanied by example input and output to demonstrate functionality.

Uploaded by

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

PWP PR 11

The document contains a series of Python programming exercises with solutions. It includes functions for comparing lists, converting tuples to dictionaries, validating student names, counting character types in a string, and checking for prime numbers. Each exercise is accompanied by example input and output to demonstrate functionality.

Uploaded by

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

Practical No.

11
#Name: Qazi Arqam Arif
#Enrollment: 2205690362
#Batch: 2

Code:

#Q.1 W.A.P function that accepts two list and returns a list whos elements sum is largest.

def large_sum_list(L1, L2):


sum1 = sum(L1)
sum2 = sum(L2)
return L1 if sum1 > sum2 else L2

L1 = [10, 22, 30, 40]


L2 = [11, 22, 33, 44, 50]

print(large_sum_list(L1, L2))

Output:
[11, 22, 33, 44, 50]

Code:

#Q2. W.A.P function that accepts two tuples, Now create a dictionary by considering first tuple
elements as key and second typle elements as values.

def tuple_to_dictionary(t1, t2):


d = {}
for i in range(len(t1)):
d[t1[i]] = t2[i]
return d

T1 = ("Quiz", "Paper Presentation", "Project Competition", "Gaming")


T2 = (32, 45, 20, 70)

print(tuple_to_dictionary(T1, T2))

Output:
{'Quiz': 32, 'Paper Presentation': 45, 'Project Competition': 20, 'Gaming': 70}
Code:

# Q2: W.A.P.P to validate name of student.

a = input("Enter your name: ")


if a.isalpha():
print("You Entered Correct Username")
else:
print("Enter only alphabets")

Output:
Enter your name: Arqam123
Enter only alphabets
---
Enter your name: Arqam
You Entered Correct Username

Code:

# Q3. W.A.P function that accepts a string and calculate the number of upper letters, lower case letters
and spaces.

def cnt_U_L(str1):
u=0
l=0
s=0
for i in str1:
if i.isupper():
u += 1
elif i.islower():
l += 1
elif i.isspace():
s += 1
return u, l, s

str1 = "Python Programming"

u, l, s = cnt_U_L(str1)

print("Upper case: ",u)


print("lower case: ",l)
print("space: ",s)

Output:
Upper case: 2
lower case: 15
space: 1

Code:

# Q. W.A.P that takes a number as a parameter and check the number is prime or not

def prime(num):
for i in range(2, num //2):
if num % i == 0:
print(num, " is not prime")
return
else:
print(num, "is prime")

prime(7)

Output:
7 is prime

You might also like