Model Lab Examination
Model Lab Examination
Model Lab Examination
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
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