0% found this document useful (0 votes)
8 views10 pages

Python Assessment

The document contains a series of hands-on Python practice exercises covering various topics including print statements, data types, arithmetic operations, string manipulation, lists, tuples, sets, dictionaries, conditional statements, flow control, list comprehension, user-defined functions, and lambda functions. Each section provides specific tasks to enhance programming skills in Python. The exercises are designed to help users apply their knowledge in practical scenarios.

Uploaded by

tapeshmandal2461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Python Assessment

The document contains a series of hands-on Python practice exercises covering various topics including print statements, data types, arithmetic operations, string manipulation, lists, tuples, sets, dictionaries, conditional statements, flow control, list comprehension, user-defined functions, and lambda functions. Each section provides specific tasks to enhance programming skills in Python. The exercises are designed to help users apply their knowledge in practical scenarios.

Uploaded by

tapeshmandal2461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Let's begin with some hands-on practice exercises

1.Using print()
1. To display a statement. For example, "Hello, How are you?"

2. Display the following pattern using print()

3. Write the alphabets 'A', 'B', 'C' on new lines using a single print function

2. Data types
4. Create a string, a numeric and boolean variables by assigning variable names. Further, check their
datatype. For numeric variable check for whole numbers and numbers with decimal point.

Declare a string variable and check its data type.

Declare a numeric variable and check its data type.

i. An interger variable.

ii. A fractional variable

Declare a boolean variable and check its data type.

5. Write a complex number and assign it the name 'comp_var'

6. Create a numberic variable and convert it to a string.

3. Arithmetic Operations
7. Evaluate 145 into 354 minus 1345 divided by 45 plus (462 plus 23) divided by 3.

8. Evaluate and print the results of the following

1353 plus 234

2355 minus 346


234 times 457

25 divided by 6

Obtain remainder of 25 divided by 6

33 raised to 4

45 divided by 6 (floor division)

2 raised to 10

5. Concatenation

9. Create two strings and concatenate them using '+' operator.

10. Concatenate the variables 'num = 34 and 'string ='How old are you?' using '+' operator.

1. String Operations
11. Create a string with the name 'country' and 'India' as its element. Perform the following on it:

Find its length.

Extract it first two letters.

12. Given the string 'Today is a sunny day.'

Write a code to get 'Today' and 'sunny'.

Obtain the last two letters.

Write the statement backwards.

2. List
1. Write a program to perform following list operations on the list given below:

a. Check the length of mix_list_1


b. Check the membership of '24' in mix_list_1

c. Concatenate the mix_list_1 and mix_list_2

d. Repeat the mix_list_2 three times

2. Write the program to multiply the two listsLists to perform multiplication:

num_list_1 = [1, 2, 3, 4]

num_list_2 = [0, 5, 2, 1]6. Write a program to perform following built-in list operations:

a. Min(list)

b. Max(list)

c. Sort the elements (use sort() and sorted() function)

d. Create a copy of a list

e. Remove element '5' from the list

Use the below list:

num_list = [4, 5, 7, -2, 0, 1]

3. Write a code to retrieve elements from a list

a. First element

b. Second last element

c. First three elements

d. Slice the list from 1st index till the last index with an increment of an index by 2

Use the below list:

mix_list = ['Python', 1, 2, 3, 'Data', True]

4. Manipulating a list:

a. Add a new element 'Data' in the given list

b. Add elements 'Excel' and 'Data' in the given list

c. Replace an element 'C' with 'C++' in the given list


Use the below list

languages_list = ['R', 'Python', 'C', 'Java']

3. Tuple
5. Write a code to perform operations on tuple:

a. Check the length of num_tuple

b. Concatenate the num_tuple and mix_tuple

c. Repeat the mix_tuple two times

Tuples to perform operations:

num_tuple = (4, 4, 8)

mix_tuple = 'John', 5, -2

6. Add a new element '4' to the given tuple

Use the tuple below:

mix_tuple = (['a', 1, True], 2, 'Science', -5)

7. Replace the elements in the given tuple:

a. Replace '2' with '3'

b. Replace 'True' in first element with 'False'

Use the tuple below:

mix_tuple = (['a', 1, True], 2, 'Science', -5)

4. Set
8. Write the program to perform following manipulations:

a. Add '7' to the given set


b. Remove '3' from a given set

c. Clear the set

Use the below set for manipulation

num_set = {1, 2, 3, 4, 5, 6}

9. Create two sets of words from the given sentences and perform the following operations:

a. Find the count of unique words in each of the sentence

b. Find the common words in both the sentences

c. Find the unique words in both the sentences

Use the sentences given below:

sentence_1 = 'We shall analyse the data using python'

sentence_2 = 'Python for data science'

10. Write a program to perform following set operations:

a. Union

b. Intersection

c. Set of all the elements of set A that are not in set B

d. Set of all the elements of set B that are not in set A

e. Symmetric difference

Use the below set:

A = {1, 4, 5, 2, 6, 3, 40, 7, 87, 4, 71}

B = {3, 42, 51, 6, 7, 8, 54, 5}

5. Dictionary
11. Write a code to add a key to a dictionary

Use the given dictionary and add a key (4:16)


square_dictionary = {1:1, 2:4, 3:9}

12. Write a program to retrieve the keys/values of dictionary

Use the dictionary

mix_dictionary = {0:3, 'x':5, 1:2}

13. Write a program to get the value for 'Age' from the dictionary

Use the dictionary

emp_record = {'Weight': 67, 'BMI': 25, 'Age': 27, 'Profession': 'CA'}

14. Write a program to create a dictionary using given keys and values

Use the keys and values to create a dictionary

key = ['a','b','c','d']

value = [1, 2, 3, 4]

15. Set the country of an employee as 'India' in the given employee record

Use the dictionary

emp_record = {'Emp_ID': 'ES001', 'Weight': 67, 'BMI': 25, 'Age': 27, 'Profession': 'CA'}

1. Conditional Statements
1. Write a program to check whether a given number is multiple of 7 (use if statement)

2. Write a code to print the maximum of two numbers (use if-else)

3. Write a program to check whether a number is positive, negative or zero (use if-elif)

Python Flow Control

4. Write a code to print table of 5 using assignment operand +=.

5. Write a program for generating a fibonacci series starting with 0 and 1 for the next 10 values using a
while loop.
6. Write a program to check whether a number is greater than the other using if statement (take the
input from user).

7. Write a code to check whether a number is divisible by 7 or not (take the input from user).

8. Write a code to find factorial of a number (take the input from user).

9. Write a program to check whether a number is prime or not (take the input from user).

10. Write a program to check whether two numbers are amicable or not (take the input from user).

11. Reverse string using a for loop (take the input from user).

12. Write a code to find the average of given numbers (take the input from user).

13. Write a program to find the area of a circle for a given radius (take the input from user).

14. Write a code to find the simple interest (take the input from user).

3. List Comprehension
15. Use list comprehension to obtain the squre root of first 10 natural numbers.

16. Use list comprehension to find the used vowels in a given sentence and/or word (take the input from
user).

17. Create a dictionary and access it values using a condition on its key. The data is given below. Let the
condidtion on the key is that it should be a even number.

Key 1 2 3 4 5

Name Aman Mohit Guari Imran Roma

Marks 24 25 26 24 27

18. Use list comprehension to find even and odd numbers from first 20 whole numbers.

19. Use list comprehension to print numbers divisible by 2 and 3 in between 1 and 100.

20. Use list comprehension to create a dictionary such that its keys are numbers from 1 to 10 and values
are the corresponding to that key are its cube.
21. Use list comprehension to extract numbers from a string

1. User-Define Function:
1. Define the python function to swap first and last value of the given list

Use the list given below:

my_list = [15, 78, 10, 45, 89]

2. Define the python function which adds two global numeric variables (1204 and 344536)

3. Define the python function to check whether the number 33 is even or odd

4. Define the python function to calculate the factorial of the number

5. Define a function to add new items(1,2,3) in the empty list

6. Write a python function to test whether the two words start with the same character or not (take the
inputs from the user)

7. Check if the string contains a vowel or not (take the inputs from the user)

8. Write the python program to get the unique values from the given list

Use the list given below:

my_list = [1,2,3,3,11,34,3,3,4,5]

9. Find the common characters from the given two strings

Use the strings given below:

string1 = 'Angel'

string2 = 'apple'

10. Define a function to perform addition, multiplication, and subtraction of the given two numbers
Use the number given below:

a = 15

b=4

11. Define a function to find the sum of all elements in the list

Use the list given below:

my_list = [34, 34, 55, 2, 56, 45]

2. Lambda Functions
12. Find the minimum of the two numbers(34 and 78) using the lambda function

2.1 Map Function


13. Calculate the square of each element from the given tuple using the map function

Use the tuple given below:

number = (11, 21, 30, 34)

14. Read the given sentence and print the length of each word in a sentence in a list using the map
function

Use the sentence given below:

sentence = 'Python for Data Science'

15. Find the remainder of all the numbers present in a list after dividing by 5

Use the list given below:

numbers = [ 74, 85, 14, 23 ]

16. Concatenate elements from the list1 with the corresponding element of list2

Use the list given below:

list1 = ['I', 'felt', 'happy', 'because', 'I', 'saw', 'the', 'others', 'were', 'happy']

list2 = [11,22,33,44,55,66,77,88,99]
2.2 Filter Function
17. Find the common elements from the given array using filter method

Use the array given below:

arr1 = ['t','u','t','o','r','i','a','l']

arr2 = ['p','o','i','n','t']

18. Remove odd numbers from the given list

Use the list given below:

numbers = [21, 23, 443, 355, 743, 823, 110, 1241, 3673, 352, 278, 37, 7]

2.3 Reduce Function


19. Calculate the sum of the numbers from 1 to 100

20. Determine the maximum of a given list using reduce function

Use the list given below:

my_list = [47,11,42,102,13].

You might also like