0% found this document useful (0 votes)
12 views2 pages

IoT (KME-553)-Ex-3

Uploaded by

Saurabh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

IoT (KME-553)-Ex-3

Uploaded by

Saurabh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT 03

OBJECTIVE

Run some python programs on Pi like:


a) Print a name 'n' times, where name and n are read from standard input, using for and while
loops
b) Handle Divided by Zero Exception
c) Print current time for 10 times with an interval of 10 seconds

SOFTWARE/COMPONENTS USED
1. PC with Arduino Thonny software
2. Raspberry Pi Pico (RP2040) board
3. Micro USB cable

a) Print a name 'n' times, where name and n are read from standard input, using for and while
loops.

CODE
# using for and for loops a = input("Enter your name: ") n =
int(input("Enter the number you want to print that times: ")) for
i in range(n): print(a) #print(i)

# using for and while loops a


= input("Enter your name: ")
n = int(input("Enter the number you want to print that times: "))
i = 1 while i <= n: print(a)
i+=1

RESULT

b) Handle Divided by Zero Exception


CODE
n=int(input("Enter the value of n:"))
d=int(input("Enter the value of d:"))
c=int(input("Enter the value of c:"))
try:
q=n/(d-c)
print("Quotient:",q)
except ZeroDivisionError: print("Division
by Zero!")

RESULT

c) Print current time for 10 times with an interval of 10 seconds

CODE
import time for i
in range(10):
localtime = time.asctime( time.localtime(time.time()) ) # DAY, DATE & TIME print
("Local current time :", localtime)
time.sleep(10)

RESULT

PROCEDURE
Click the run button and save it on the Raspberry Pi Pico board. Save the file as main.py.

RESULT
We have successfully run python programs on Raspberry Pi.

You might also like