0% found this document useful (0 votes)
3 views

Python End-Sem 2023

Uploaded by

kalpitnagar106
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python End-Sem 2023

Uploaded by

kalpitnagar106
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

End-Sem, B. Tech.

I-EC (II Sem) U22E(oo4


Python
Name: Date:
Roll No:
question must be attempted continuously
Question number should be mentioned clearly, and all parts of a
or in correct order.
[Marks]
[Co]
Python code snippets: (2+2
Q1. Write down all the problems/errors in the following +1+1]
a) from machine import Pin [COs]
button.Pin = (27, Pin.IN)
while False:
print(value. button()
sleep(0.5)
b) fruits = ["banana", "potato", "apple"]
for x in class:
for y in fruits:
print (x,y)
c) import re
bxt = "The rain in Spain"
X= re.search (("^The.*Spain$", txt)
d) myorder-"| have a (carname} car, it isa {model)."
print(myorder.format(carname='Maruti',model='Alto'))
Python code snippets: [2+2
Q2. Find the outcome of each of the print statements of the following +1+1]
a) x=OxFO
[COs]
y= OxOF
print ((x | y) -((x>>4)+ (y>> 4)))
(b) y= [x if (x %3) ==0 else (x%2) for xin range (0, 8, 2)]
print (y)
(c) x= [1,2,1,3,1,4])+ (2,3,2,4,2,5]
print( list (set (tuple (x) )))
(d) x=0
y=-1
print (str (x | (~y))
Q3. Write one line explanation of each of the following options in the file handing in Python: (4]
(b). "a" (c). "w" [CO4]
(a). ""
(d). "x" (e). "t" (f). "b"
Q4.
Write one line explanation of each of the following attributes of the "machine.Pin" class: [4)
(a). Pin.IN (b). Pin.OUT (c). Pin.OPEN_DRAIN [CO1]
(d). Pin.ALT (e). Pin.PULL_UP (f). Pin.PULL DOWN
05. Write aPython program that takes two numbers as input, finds the highest common factor (5]
[CO3]
(h.c.f.) of these two numbers using iteration, and prints the result.
Q6. Write a Python program that takes a decimal number as input and checks whether it is (5]
correct. If found correct, it converts the integer part of the input decimal number to binary [CO3]
using a loop and prints the result.
Write a Python program to calculate the factorial of an integer using: [8]
Q7.
a). iterative Approach [CO3]
b). recursion
Q8.
Write comments for each line of the following Micropython code and write a conclusion [6]
about what the code is written for. (Co1)
Line Code
Number
1 from machine import Pin
2 from time import sleep
motion = False
4 def handle_interrupt(pin):
5 global motion
6 motion =True
global interrupt_pin
interrupt_pin = pin
9 led = Pin(12, Pin.OUT)
10 pir = Pin(14, Pin.IN)
11 pir.irq(trigger=Pin.IRQ_ RISING, handler=handle_interrupt),
12 while True:
13 if motion:
14 print('Motion detected! Interrupt caused by:", interrupt_pin)
15 led.value(1)
16 sleep(2)
17 led.value()
18 print('Motion stopped!")
19 motion = False

Q9. (a). Write comments for each line of the following Python code [6]
(b). Write a conclusion about what the code is written for. [CO1]
(C). Write the outcome of the "print" function and the value of the variable x after the
execution of the code.
Line Code
Number
1 def my_func (k):
2 if(k> 0):
3
result = k+my_func (k-1)
4 print(result)
else:
6 result =0
7 return result

X= my_func(7)

You might also like