Assignment 1
Assignment 1
Module-1
1. Define variables and data types in Python. Explain the rules for naming variables in Python with
suitable examples of both valid and invalid names.
2. Describe Arithmetic Operators, Assignment Operators, and Comparison Operators with example.
3. Explain the working of string concatenation and string replication in Python with example.
4. What are the different flow control statements supports in python. Explain all (Conditional, loop and
Unconditional) with syntax and suitable example program and flow chart.
5. Compare break and continue keywords. Demonstrate the usage of both using a code snippet.
Programs:
6. Develop a Python program
i. To generate the sequence 0,1,1,2,3,5,8….up to Nth term, reading N from the console and print
the sequence. Or Fibonacci Series
ii. To read the student details like Name, USN, and Marks in three subjects. Display the student
details, total marks and percentage with suitable messages.
iii. Given a vehicle’s fuel level (in percentage), write a program using comparison operators to
check if the fuel level is below 15%, if it is below 15% print a “Low fuel warning” Otherwise,
it should print a message like "Fuel level is sufficient"
iv. To print the grades of a student based on the percentage of marks entered by the student.
Consider the grades to be
Distinction if the marks is between 85 to 100
First class the marks is between 60 to 79
Second class the marks is between 50 to 59
Fail if less than 50.
Module-2
1. Demonstrate the use of local and global scope of variables in python with example code snippet. How
can you force a variable in a function to refer to the global variable?
2. What is a function in Python? Explain how to define a function with parameters and return values, including
an example.
3. What is Exception Handling? How exceptions handled in Python? Apply the concept of exception handling
code to handle divide-by-zero error situation.
4. Illustrate use of following with syntax and appropriate example remove() , pop (), sort(), append(),
index(), sort(), random.choice(), random.shuffle(). .
5. Read N numbers from the console and create a list. Develop a program to print mean, variance and
standard deviation with suitable messages.
6. Write a function to calculate the factorial of a number. Develop a program to compute binomial
coefficient (Given N and R).
7. Consider subject = ['Structures', 'Python', 'C', 'C++', 'Java', 'OOPS']
Write python statements to perform the following operations and display the output after each step:
i. Insert the subject "DMS" at the 2nd position from the end of the list
ii. Update the subject at index 5 to "BigData".
iii. Check whether "Java" is present in the list subject.
iv. Print the list in reverse order.
8. For list=[‘hello’, ‘how’, [1,2,3], [10,20,30]] what is the output of the following statement
i. print(list [: :])
ii. print(list [: ])
iii. print(list [-3][0])
iv. print(list [2][ :-1])
v. print(list [0][ ::-1])
vi. print(list[0][2])
vii. print(list[::-2])
viii. print(list[1:4:2])
9. For data = [9, 3, 7, 1], Write the output for the following statements:
i. data.append(5)
ii. data.sort()
iii. data.insert(0, 10)
iv. data.remove(3)
v. del data[2]
vi. print(data)