Assignments: Python Programming

List of Assignments

Assignment – 01:

[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

Assignment – 02:

[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

Assignment – 03:

[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

[2]. Reverse the string

[3]. Print the same string 10 times by repetition.

[4]. Concate ‘I am Fine’ with S1

Assignment – 04:

[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]. Given 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: 12

Assignment – 05:

[1]. 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

[2]. 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?

[3]. Consider the same List L and perform the 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?

Assignment – 06:

[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 G.

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

Assignment – 07:

[1]. Print odd numbers between 1 to 20 using while loop

[2]. Print even numbers between 40 to 50 using while loop (both numbers included)

[3]. Print the following output using the while loop:

*

* *

* * *

* * * *

* * * * *

Assignment – 08:

[1]. Compare digits of two numbers and check if both numbers are same or not

[2]. Add square of digits of number and print the sum

[3]. Print number, its square and its cube for 1 to 10 numbers:

Assignment – 09:

[1]. Write a program using while loop to count elements greater than 50 from given list

[2]. Write a program using while loop to find perfects square numbers less than 10 from given list

[3]. Write a program using while loop to print list in reverse order

Assignment – 10:

[1]. Write a program to implement the following patterns using while loop:

1 2 3
2 3
3
1 2 3
1 2
1
1
2 1
3 2 1

Assignment – 11:

[1]. Write a program to implement the following patterns using while loop:

1 2 3
 2 3
  3
1 2 3
 1 2
  1
  1
 2 1
3 2 1

Assignment – 12:

[1]. Write a program to implement the following patterns using while loop:

3 2 1 
  3 2 
    3
3 2 1 
 3 2 
  3
3 2 1
  2 1
    1

Assignment – 13:

[1]. Print numbers between 1 to 100 which are multiple of 5 using for loop

[2]. Print even numbers between 70 t0 90 in reverse order using for loop

[3]. Print numbers between 51 to 78 which are divisible by 4 using for loop

Assignment – 14:

[1]. Print Armstrong Number between 1 to 100 (Hint: Use while and for loop)

[2]. Print the first three Armstrong numbers between 1 to 100 (Hint: Use while and for loop)

[3]. Initialize the list of numbers. Cout and print the number of positive, negative and zero elements in the given list using for loop

Assignment – 15:

[1]. Write a function reverseList(L) to print list in reverse order

[2]. Write a function MulTable(m, n) which prints the multiplication table of m up to n

Assignment – 16:

[1]. Implement lambda function to print if a given number is positive or negative

[2]. Implement lambda function to print if the first number is larger or smaller than the second number

[3]. Using map and lambda function, multiply each element of the list by 2

[4]. Create a list of fruits. Using map and lambda function, convert all fruit names to upper case.

[5]. Creat list of temperature values. Using map and lambda function, convert the temperature in ferenhite.

Leave a Reply

Your email address will not be published.