Model Lab Examination

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

MODEL LAB EXAMINATION

Course Code : 18ECO109J Course Title : Embedded System Design Raspberry Pi


Reg. No. : RA1811030010062 Name : SACHIN MOTWANI
Semester : V Semester Year : III Year

Date of Exam. : 16th November 2020


Name of Lab faculty member : V. Padmajothi

Aim:
To execute given programs using python 3
Task:
1. A. Write a Python Program to generate a temperature profile dictionary (values in range: 30 to 100)
for ten days randomly (from August 1 to August 31).
(i) Check whether August 10 data exist in a dictionary or not.
Hint: Key = Date and Value = Temperate.
(ii) Find the count of temperature 30, 40 in the dictionary.

B. Write a function called showNumbers( ) that takes a parameter called limit. It should print all the
numbers between 0 and limit with a label to dentify the even and odd numbers. For example, if the limit
is 3, it should print:
0 EVEN
1 ODD
2 EVEN
3 ODD

Algorithms:

For ques 1a

1. Import the random module to generate random numbers


2. Define a checkKey function :
If key is in the dictionary:
Print(“YES”)
Else
Print(“NO”)
[END OF IF]
3. Define an empty dictionary and empty list
4. Run a loop 10 times:
Generate random numbers between 1 and 31 and save them in list
[END OF LOOP]
5. Run a loop for all elements in the list
Generate random numbers between 30 and 100 and store it as temp with each value of the list as
a key
[END OF LOOP]
6. Use the checkKey function to check for the value of 10 aug
7. Use the .count() inbuilt function to count the keys of 30 and 40 and print it.

For ques 1b
1. Declare the checkeven function as below
Input the number
If number%2 equals 0
Return EVEN
Else
Return ODD
[END OF IF]
2. Input the limit
3. Run a loop from 0 to limit+1
Print the number
Compute checkeven function for the number and print the retrn value
[END OF LOOP]
Programs:

For ques 1a
import random
def checkKey(dict, key):
if key in dict.keys():
print("Present")
else:
print("Not present")

d={}
l=[]
for i in range(10):
x = random.randint(1,31)
y = str(x) + " Aug "
l.append(y)
for i in l:
d[i]=random.randint(30,100)
print(d)
checkKey(d,"10 Aug ")

x1 = list(d.values()).count(30)
x2 = list(d.values()).count(40)
print("The cpunt of 30 is: ",x1)
print("The cpunt of 40 is: ",x2)
For ques 1b
def checkEven(n):
if(n%2 == 0):
return "EVEN"
else:
return "ODD"

def showNumbers(limit):
for i in range(limit+1):
s = str(i) + " " + checkEven(i)
print(s)

if __name__ == "__main__":
n = int(input("Enter the limit value: "))
showNumbers(n)

Result:

For ques 1a
For ques 1b

Output Video link:


https://drive.google.com/file/d/1o210ykxNvslWGUL9mXwFPdWSgidoScq7/view?usp=sharing
Scanned by TapScanner
Scanned by TapScanner

You might also like