Assignments: Python Programming

List of Assignments

Assignment – 01:

  1. What is the difference between HTML and Python?
  2. Name the founder of Python
  3. Enlist a few programming languages
  4. Differentiate compiler and interpreter
  5. Name a few interpreter-based languages.
  6. Name a few compilation-based languages.
  7. What do you mean by open-source software?
  8. Name at least five open-source software/languages.
  9. Name at least five non-open source/commercial software/languages.
  10. List 10 different editors and also mention for which purpose we can use them.

Assignment – 02:

  1. What do you mean by the portability of software?
  2. List out a few developer communities (e.g. Stackoverflow)
  3. Why python is called a general-purpose language?
  4. List out a few services which use python.
  5. Enlist 5 programming languages with their use in a specific domain

Assignment – 03:

[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 – 04:

[1]. Find a binary number of the 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 – 05:

Instruction: Entity enclosed in << >> indicates variable. Do not put the static value there.

[1]. Write a code to print: Hello “<<YOUR NAME>>”

[2]. Write a code to get the integer part of a division operation.

Explanation: If a/b = 7.34, then your output should be 7

[3]. Write code to get output in exactly the following format:

1 * 1 = 1

2 * 2 = 4

3 * 3 = 9

4 * 4 = 16

[4]. Assign your name and age in variables called myname and myage. Your output should be exactly as follow:

My name is ‘<<YOUR NAME>>’, and I am “<<YOUR AGE>>” old

[5]. Print the following pattern without using a loop

* * * * *
*       *
*       *
*       *
* * * * *

Assignment – 06:

[1]. Do a study of the google colab environment

[2]. Understand the functionality of the Jyupyter Notebook editor on google colab

[3]. Explore how files are managed on google drive by experimenting with google collab

[4]. write a program that reads your name, your gender and your hobby. And it should display output as Hi Folks, I am ‘YOUR NAME’, “YOUR GENDER” and I like YOUR HOBBY

[5]. Write a program to demonstrate various operators such as addition, subtraction, multiplication, division, integer division and exponent.

[6]. Let a = 10, b = 20, c = 30. Use print( ) function such that your output should look like : a = ’20’, “b = 30”, c = “10”

Assignment – 07:

Note: Syntax <<VARIABLE>> represents the variable, don’t replace it with a static string anywhere.

[1]. Read your name in variable <<MYNAME>> and display output as follow: My name is “<<MYNAME>>” and length of my name is ‘<<LENGTH OF MYNAME>>’

[2]. Print ‘<<MYNAME>>’ length of your name times: i,e, if MYNAME = ‘RAM’ then the output should be ‘RAMRAMRAM’ (length of MYNAME is 3), if MYNAME = ‘ALEX’ then the output should be ‘ALEXALEXALEXALEX’ (length of MYNAME is 4).

[3]. Read your first name and last name in variables <<FNAME>> and <<LNAME>>. Display output as “I am <<FNAME >> <<LNAME>>”

[4]. Write a code that demonstrates the use of single-line and multiline comment

[5]. Read ‘Python’ in variable <<LANGUAGE>>. Read ’70 billion’ in variable <<DEVELOPERS>>. Using key-value pair representation, format the output as follow: ‘Python’ is the most popular language across the globe. “70 billion” developers use ‘Python’ as their first choice language.

Assignment – 08:

[1]. Consider string S1 = “Hello Python, I fall in love with you”. Write a python code to get the following output for string S1.

  1. P
  2. Python
  3. Hello
  4. u
  5. you
  6. Print index of first character ‘w’
  7. Replace ‘Python’ with ‘HTML’ in S1
  8. Replace each occurrence of ‘l’ with ‘L’ in S1

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

  • Find the index of character ‘o’
  • Replace ‘You’ with ‘Dogs’
  • Slice string to print the following:
    • eel
    • Are
    • Hello How
    • Are You

[3]. Reverse the string

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

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

Assignment – 09:

[1]. Consider string S1 = “Hey Dude, I Love ICE HOCKEY”. Write a python code to get the following output for string S1.

  1. print all occurrences of ‘y’
  2. Output: Hey dude, I love ice hockey
  3. Output: Hey Dude, I Love Ice Hockey
  4. Reverse the string
  5. Print maximum and minimum characters in S1
  6. Check S1 is starting with ‘Hi’
  7. Check if S1 is ending with ‘HOCKEY’
  8. Replace ‘ICE HOKECY’ in S1 with ‘SOCCER’

Assignment – 10:

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

[2]. State the advantages of a 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 – 11:

[1]. Differentiate Tuple and list

[2]. Perform the following operations on Tuple: T = (11, 22.2, ‘a’, ‘Python’)

  • Print id of T
  • Repeat the tuple T thrice
  • Concate appropriate tuple to T, so that T will become (11, 22.2, ‘a’, ‘Python’, (1, 2), [‘Hello’, ‘Java’], (101, [‘A’, ‘B’, (‘x’, ‘y’, ‘z’)]))

[3]. Perform operations on T = (11, 22.2, ‘a’, ‘Python’, (1, 2), [‘Hello’, ‘Java’], (101, [‘A’, ‘B’, (‘x’, ‘y’, ‘z’)])) to get following outputs:

  • ‘Python’
  • [‘Hello’, ‘Java’]
  • [‘A’, ‘B’, (‘x’, ‘y’, ‘z’)]
  • ‘y’
  • 101
  • ‘A’, ‘B’

Assignment – 12:

[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 form list L:

  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 with 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” with ‘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 – 13:

[1]. Explain the difference between a list and a tuple (Hind: print id)

[2]. Take a list of your choice and demonstrate the following operations on that:

  • Repetition
  • Concatenation
  • Indexing
  • Update
  • Count the occurrence of element
  • Find the length of the list
  • Check membership of an element in the list
  • Explain with an example: Append & Extend functions
  • Insert
  • Demonstrate with an example: Remove and del

Assignment – 14:

[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 than 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 – 15:

[1]. Consider the list L = [11, 22, 33, (‘a’, ‘b’, ‘c’), 55, [1, (2, 3)] ]

State the output for the following operations on list L:

Note: For all tasks, the output of the current task shall be considered as input to the next task

  • Find the length of the list L
  • Insert element 44 after 22
  • Which element is selected as an output on the second pop
  • Insert (111, 222, 333) as a single element at the end of the list
  • Insert (444, 555, 666) as individual elements of the list
  • Print every alternate element of the list in reverse order
  • Print the index of element (444, 555, 666)
  • Print element 3 from L
  • How dictionary differs from a list?
  • Create a dictionary having name and age as key and appropriate values as their value

Assignment – 16:

[1]. Read the age of a person in a variable named << AGE >>, and print one of the following as an output based on the value of << AGE >> variable:

  • if AGE < 15: “You are Kid”
  • If 15 < AGE < 25: “You are Young”
  • If 25 < AGE < 55: “You are an Adult”
  • if AGE > 55: “You are a senior citizen”

[2]. Read any color in variable << ColName >>.

  • If the value of color is any of this: ColName = [‘red’, ‘green’, ‘blue’, ‘cyan’, ‘magenta’ ‘yellow’], then print ‘I LOVE THIS << ColName >> Color’,
  • Otherwise, print ‘Oooppps…. You have a bad choice of colors! Get lost from here’

Assignment – 17:

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

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

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

*
* *
* * * 
* * * *

Assignment – 18:

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

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

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

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

[5]. Write a program using while loop to find perfect square numbers less than 10 from the given list

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

Assignment – 19:

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

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

Assignment – 20:

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

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

Assignment – 21:

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

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

Assignment – 22:

[1]. Print the first n numbers in reverse order using a while loop.

Input: n = 8

Output: 8 7 6 5 4 3 2 1

[2]. Print square and cube of first n numbers using while loop

Input: n = 5

Output:

  • Square of 1 is 1 and Cube of 1 is 1
  • Square of 2 is 4 and Cube of 2 is 8
  • Square of 3 is 9 and Cube of 3 is 27
  • Square of 4 is 16 and Cube of 4 is 64
  • Square of 5 is 25 and Cube of 5 is 125

[3]. Write a program to find the factorial of n (denoted as n!).

n! = 1 * 2 * 3 * … * n

Input: 5

Output: 120

Input: 6

Output: 720

Assignment – 23:

[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 – 24:

[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 – 25:

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

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

Assignment – 26:

[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]. Create a list of temperature values. Using map and lambda function, convert the temperature in ferenhite.

Assignment – 27:

[1]. Compute the sum of the first N numbers using recursion

[2]. Print first N numbers in reverse order using Recursion

[3]. Add digits of a number using Recursion

[4]. Reverse the number using recursion

[5]. Reverse the string using recursion

Assignment – 28:

[1]. Take list L1 and L2 of same size. Implement where() function such that for every even element in L1, corresponding elements in L2 should be doubled and for every odd elements in L1, corresponding elements in L2 should be half.

EXAMPLE:

Input: L1 = [1, 3, 4, 7, 5, 6, 8], L2 = [11, 55, 33, 44, 22, 77, 88]

Output: L2 = [5.5, 27.5, 66, 22, 11, 144, 176]

[1]. Implement a function NonZero(L), such that the function should return False if there is any zero in the list, and True otherwise

EXAMPLE:

if L = [1, 2, 3, 4, 5], Output: True

if L = [1, 2, 3, 0, 5], Output: False

Assignment – 29:

[A]. Read a list and find is mean and standard deviation without using standard functions

[B]. Read the sorted list and find its median without using the standard function.

Assignment – 30:

[1]. Create the series with the following data and index:

Data: Name of Any Seven movies

Index: First letter of the movie

Note: Use the list to create the series

[2]. Create the above series using dictionary

[3]. Create new series from the series created in step 1, such that new series contains data from odd positions of old series only.

[4]. Convert the above series in list

Assignment – 31:

Create a data frame having rows with the following details:

Row 1: (‘Alex’, 23, 67, ‘A’)

Row 2: (‘Bob’, 24, 78, ‘B’)

Row 3: (‘Peter’, 22, 60, ‘B’)

Row 4: (‘James’, 26, 75, ‘C’)

Perform the following operations on this data frame:

  • Change column names to NAME, AGE, WEIGHT, GRADE
  • Change row names to R1, R2, R3, R4
  • Print first two and last two rows using head and tail function
  • Print first two and last two rows using loc function
  • Print first two and last two rows using iloc function
  • Print first and last row
  • print first and last column

Assignment – 32:

Load ‘SZ27.csv’ file in dataframe and perform following operations on it

  • Print the row with maximum temprature
  • Prind date and minimum pressure
  • Print temprature and humidiy on Rain event
  • Ilulustrate various kinds of filling techniques to fill missing data
  • Print rows with all attributes present
  • Print rows with maximum 1 missing attributes
  • Print rows with maximum 2 missing attributes
  • Drop rows in which all attributes are missing

Assignment – 33:

Load ‘jamesbond.csv’ file in dataframe and perform following operations on it

  • Fill missing values using any method
  • Print film names and its budget for actor ‘Sean Connery’
  • Print 5 most recent films data from the dataset
  • Print 5 oldest films data from the dataset
  • Get all details of movie released in year 1962
  • Set film as index and sort all movies based on index in descending order
  • List the movie names directed by ‘Terence Young’