Python Programming RS

List of Assignments

Lecture 1: 12/05/2022

No Assignment: Reading on basics of python

Lecture 2: 01/06/2022

No Assignment: Reading on Compiler and Interpreter

Lecture 3: 21/06/2022

No Assignment: Installation of Anaconda and understanding Jupyter Notebook

Lecture 4: 12/07/2022

[1]. Consider variables A = 8 and B = 6.

Write a program to demonstrate various arithmetic operators

[2]. Consider x = 30 and y = 30

Write a program to demonstrate various comparison operators

Lecture 5: 14/07/2022

[1]. Find binary number of following decimal (Using pen and paper):

45, 127, 513, 1023, 2049

[2]. Convert the following binary number to decimal (Using pen and paper):

1000101, 1110101, 1111, 10101010111

[3]. Write a program to demonstrate various logical and bitwise operators

[4]. WAP to demonstrate the use of membership operators

Lecture 6: 19/07/2022

Lecture 7: 21/07/2022

[1]. Consider the string S1 = ‘Hello How Are You?’

Find index of character ‘o’

Replace ‘You’ with ‘Dogs’

Slice string to print following:

  • eel
  • Are
  • Hello How
  • Are You

Reverse the string

Print the same string 10 times by repetition.

Concate ‘I am Fine’ with S1

Lecture 8: 16/07/2022

Lecture 9: 28/07/2022

[1]. What do you mean by mutable and immutable objects?

[2]. State the advantages of tuple over a string

[3]. Differentiate: Tuple vs. List

[4]. Give the Tuple: T = ((1, 2, (‘Hello’, 11, 12, “Python”)), 21, 22, [31, 32, (“Zain”, 13, “Sania”, 12), “World], 41, 42). Perform operations to get the following outputs

  • Find the length of T and match it with your understanding
  • Output: (1, 2, (‘Hello’, 11, 12, “Python”))
  • Output: 11
  • Output: P
  • Output: 21, 22
  • Output: Zain
  • Output: Sania
  • Output: S
  • Output: W
  • Output: 21, 23

Lecture 10: 02/08/2022

Lecture 11: 04/08/2022

Consider the list L = [1, (2, 3), [4, 5, (6, 7, [8, 9, 10], 11, 12), 13], (14, ‘Hello’, [15, “Python”, “HTML”]) ]

Write python code to get the following output:

  1. [8, 9, 10]
  2. Python
  3. M
  4. 5
  5. 8, 9

Consider the same list L and write a python code to get the following output: (Take care of exact formatting)

  1. The First element of the list is 1, and the last element of the list is “HTML”
  2. The First element is 1, the second element is (2, 3), the third element is [4, 5, (6, 7, [8, 9, 10], 11, 12), 13] and the last element is (14, ‘Hello’, [15, “Python”, “HTML”])
  3. I like ‘Python’ over ‘HTML’ (Note: Python and HTML should be fetched from L, do not just type them in the print function)
  4. Replace HTML by Java and print the following string as an output: Hello ‘Python’, I am ‘java’, How are you?

Consider the same List L and perform following operations on it:

  1. Replace ‘Hello” by ‘Hi’
  2. Count occurrence of ‘o’
  3. Fetch and reverse the word HTML
  4. Can we find Max, Min and the sum of L? Why?

Lecture 12: 09/08/2022

Lecture 13: 11/08/2022

[1]. Consider the list L = [30, 10, 20]. Your output should be:

  • In L, the maximum number is 30, the minimum number is 10 and the average is 20. The length of L is 3.

[2]. Create sets as follow: A = Set of even numbers less then 12, B = Set of perfect squares less than 30. Perform the following operations on two sets:

  • Union of sets
  • Intersection of sets
  • Difference of sets

[3]. Create the dictionary in different ways using the following keys and corresponding values as follows:

Keys = {1, 2, 3, 4, 5, 2, 3}

Values = {‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’}

[4]. Perform pop operation on the previous dictionary to remove element C.

[5]. Add (7, ‘Seven’) key-value pair to the dictionary used in the previous example.