Lab 1

Download the ipynb file python.ipynb.

Arrays

Note Exercise 1

Write a Python program to find the second largest element in an array.

Note Exercise 2

Write a python program that moves all the zeros in the array to the end while keeping the order of other elements same

Functions

Note Exercise 3

Write a Python program to generate the first n numbers from the Fibonacci sequence. In the Fibonacci sequence, each number is sum of the previous two numbers and the series looks like this: 0, 1, 1, 2, 3, 5, 8, 13, \ldots

Note Exercise 4

Write a Python program that takes an integer and returns the sum of its digits.

Strings

Note Exercise 5

Write a Python program to count the number of strings where the string length is 2.

Note Exercise 6

Write a Python program to check if string ‘s2’ is subset of string ‘s1’.

Note Exercise 7

Write a Python program to check if a string is a palindrome.

Loops

Note Exercise 8

In Python, matrix is represented as a list of lists. Write python program to perform matrix multiplication.

Note Exercise 9

Write a Python program to reverse the word in a given sentence without changing the word order in sentence. For example, “hello world” to “olleh dlrow”.

Conditionals

Note Exercise 10

Write a Python program to check if the year is a leap year.

Note Exercise 11

Write a Python program that returns grade based on the following criteria: * 90 to 100 -> Grade A * 80 to 89 -> Grade B * 70 to 79 -> Grade C * 60 to 69 -> Grade D * Below 60 -> Fail