0% found this document useful (0 votes)
4 views3 pages

Iot Lab1

The document contains a series of Python programs designed to perform various tasks such as greeting users, performing arithmetic operations, calculating areas of shapes, handling exceptions, and reading files. Each program is presented with input prompts and outputs specific results based on user input. The code snippets demonstrate basic programming concepts and user interaction in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Iot Lab1

The document contains a series of Python programs designed to perform various tasks such as greeting users, performing arithmetic operations, calculating areas of shapes, handling exceptions, and reading files. Each program is presented with input prompts and outputs specific results based on user input. The code snippets demonstrate basic programming concepts and user interaction in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Bengaluru ##

P1. ##ALS, print Hello <name


read a name and
##AProgram tO

Name Here")
#print("Please Enter Your
Name Here:\n")) #get the input from console
name = input("Please Enter Your

print("Hello " + name)

Bengaluru ##
## ALS, difference, product
P2.
Program to read twO numbers dnd diSplay Sum,
#4 A
and division

Number")
print ("Enter First
num1 = input ()

Number")
print ("Enter Second
num2 = input ()
t *
print ("*** *")
"+str (int (num1 ) +int (num2)))
print ("Sum of Given numbers is :
"+str (int (numl )-int (num2) ))
print ("Difference of Given numbers i s :
"+str(int (numl) *int (num2) ) )
print ("Product of Given numbers is: "+str (int (numl)/int (num2) ) )
print ("Division of Given numbers is :
**** ** ***
* * * * *** * ** n )
nrint (" ******** ****

P3. ## ALS, Bengaluru ## given


## A Program to calculate
number of words and characters of a
sring
print ("Enter a sentence ")
sentence = input ()

words = sentence. split()

Word count = 0
character count = 0

for wOrd in words:


WOrd count += 1
character count += len (word)
: WOrd count)
Words in the sentence are excluding spaces are
print ("Total Numbers of sentence
characters in the
print ("Total Numbers of
: " ,character count) including spaces are
Numbers of characters in the sentence
print ("Total
:",character count+word count-l)
P4. ## ALS, Bengaluru ##
## A Program to get Area of a selected shape.
1. Rectangle
2. Triangle
3. Circle

while True:
print ("******* ***

print ("Select the Shape that you want to **********")


calculate Arean)
print (""" 1. Rectangle
2. Triangle
3. Circle
4. Exit """)

choice = input ()
if (choice == '1'):
print ("Enter the Width of the
width = int (input ()) Rectangle in meters")
print ("Enter the height of the
height = int (input()) Rectangle in meters")
print ("The area of a Given
Square meters ") Rectangle is ", width*height
continue
elif (choice == 12'):
print ("Enter the Base value of
base = int (input ()) the Triangle in
mneters")
print ("Enter the height of the
height = int (input () ) Triangle in meters")
print ("The area of a Given
Square meters ") Rectangle is ",
0.5*base*height
Continue
elif ( choice ==3'):
print ("Enter the Radius of the
radius = int (input () ) Circle in meters")
print ("The area of a Given Circle is
", 3.14
Square meters ") *radius*radius
Continue
elif (choice == "4'):
break
else:
print ("Please enter a valid number from
Continue the menu")

print ("Thank Youw

P5. ## ALS, Bengaluru ##


## A Program to print a name n
CimeS where name and n values has t ba
input from standard input
print ("Enter Your name
name = input ()
nrint ("Enter How many tlmes yOu want to print your name")
n = int (input () )

for i in range (n) :


print (name)

P6. ## ALS, Bengaluru ##


Divide By Zero Exception
## A Program to Handle
: ")
print ("Enter Numerator Value
numl = int (input ())

: ")
print ("Enter Denominator value
num2 = int (input ())

try:
result = numl/num2
is : ", result)
print ("The Division of Given Numbers
except ZeroDivisionError:
Denominator should not be Zero")
print ("Divide By zero Error. The

P7. ## ALS, Bengaluru ## seconds


time with an interval of 10
## A Program to print current
import time

# seconds passed since epoch

for i in range (10):


to you as a float values
seconds = time.time () #it will give
gives to you as a
local time = time.ctime (seconds) #it will
current local time
time)
print ("Local time:", local
time. sleep (10)

P8. ## ALS, Bengaluru ##


print No of Words in each Line
## A Proqram to Read a file and
read file
filel = open('myfile.txt', 'r') #to of filel ,if we
#to read the each line
Lines = filel.readlines () (1)
filel then write readlines
want only one line of also
#print (Lines) #we can able print
i=0
for line in Lines:
i += 1
())
count = len (line.split of WOrds ", count)
print ("Line ", i, "No

You might also like