Python-Midsem-v2
Python-Midsem-v2
Roll No:.............................................................
DEPARTMENT OF ELECTRICAL ENGINEERING
5th SEMESTER B. Tech (EEE) MID SEMESTER EXAMINATION - MONSOON SEMESTER 2024-‘25
EE2021E Python Programming and Applications
Time: 2 Hours Maximum: 30 Marks
(Answer all questions.)
2. List the advantages of Python over other programming languages. What module must
be imported to print random number in a given range? (1 mark)
3. Write a Python program that accepts a word from the user, reverses it, prints the
reverse word and indicates whether it is palindrome or not. (Use for loop and if
statement) (3 marks)
4. Write a Python program to check the validity of password input by users. The password
must be 8 characters long, must contain atleast one capital, one small, one special
character (!,@,#,$,&) and one number. If the criterion is met then output of the program
must be password saved successfully. If the criterion is not met then it must output
invalid password and ask a new password and repeat until criterion is met (6 marks)
5. Write a Python program (using while loop) that will calculate the binary representation
of a given number (3 marks)
6. Write the syntax for list comprehension and mention its advantage over for loop. Using
list comprehension print even numbers in a given range (3 marks)
9. What will be the output of the following Python code and explain your answer in terms
of scope of variables (the code is free from indentation and syntax errors) (3 marks)
x=1
def func():
global x
x=11
y=12
print(f'local x is equal to {x}')
print(f'local y is equal to {y}')
def bar():
print(f'bar sees x equal to {x}')
bar()
func()
print(f'global x is equal to {x}')
10. a. Write the syntax for list, tuple and dictionary and give one example for each. Mention
their characteristics. (3 marks)
b.Give the difference between set and frozen sets along with necessary examples.
(2 marks)