Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Fa22 BCS 222

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

COMSATS UniverSiTy iSlAMAbAd

(SAhiwAl CAMpUS)

ASSignMenT # 01

SUbMiTTed by: Muhammad abu bakar

regiSTrATiOn nO: fA22-bS(CS)-222

SUbMiTTed TO: Mr. Muhammad Ahmad Farid


Lab 01
Activity 1:
Let us take an integer from user as input and check whether the given value is
even or not. If the given value is not even then it means that it will be odd. So
here we need to use if-else statement an demonstrated below.
Solution:

Output:
Activity 2:
Write a Python code to keep accepting integer values from user until 0 is
entered. Display sum of the given values.
Solution:

Output:
Activity 3:
Write a Python code to accept an integer value from user and check that
whether the given value is prime number or not.
Solution:

Output:
Activity 4:
Accept 5 integer values from user and display their sum. Draw flowchart before
coding in python.
Solution:

Output:
Activity 5:
Calculate the sum of all the values between 0-10 using while loop.
Solution:

Output:
Activity 6:
Take input from the keyboard and use it in your program.
Solution:

Output:
Lab 02
Activity 1:
Accept two lists from user and display their join.
Solution:

Output:
Activity 2:
A palindrome is a string which is same read forward or backwards. For example:
"dad" is the same in forward or reverse direction. Another example is
"aibohphobia" which literally means, an irritable fear of palindromes. Write a
function in python that receives a string and returns True if that string is a
palindrome and False otherwise. Remember that difference between upper and
lower case characters are ignored during this determination.
Solution:

Output:
Activity 3:
Imagine two matrices given in the form of 2D lists as under; a = [[1, 0, 0], [0, 1,
0], [0, 0, 1] ] b = [[1, 2, 3], [4, 5, 6], [7, 8, 9] ] Write a python code that finds
another matrix/2D list that is a product of and b, i.e., C=a*b.
Solution:

Output:
Activity 4:

Solution:
Output:

Activity 5:
Imagine two sets A and B containing numbers. Without using built-in set
functionalities, write your own function that receives two such sets and returns
another set C which is a symmetric difference of the two input sets. (A
symmetric difference between A and B will return a set C which contains only
those items that appear in one of A or B. Any items that appear in both sets are
not included in C). Now compare the output of your function with the following
built-in functions/operators.
✓ A.symmetric_difference(B)

✓ B.symmetric_difference(A)

✓A^B

✓B^A
Solution:
Output:
Activity 6:
Create a Python program that contains a dictionary of names and phone
numbers. Use a tuple of separate first and last name values for the key field.
Initialize the dictionary with at least three names and numbers. Ask the user to
search for a phone number by entering a first and last name. Display the
matching number if found, or a message if not found.
Solution:

Output:

You might also like