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

Python

Uploaded by

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

Python

Uploaded by

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

Exception Name

Description
EOFError Raised when one of the built-in functions (input( )) hits an end-of-file condition (EOF)
without reading any data.
JOError Raised when an l/O operation (such as a print( ), the built-in open( ) function or a
method of afile object) fails for an /O-related reason, e.g., "file not foun" or"diskful".
NaneError Raised when an identifier name is not found.
IndexError Raised when a sequence subscript or index is out of range, e.g., from a string of length 4 if
you try to read a value of index like 4 or more i.e., string[4, string[5), stringl-5] etc. will
raise exception as legal indexes for astring of length 4 are 0, 1, 2, 3and -l, -2, -3, 4only.
InportError Raised when an import statement fails to find the module definition or when a from ..
import fails to find a name that is to be imported.
TypeError Raised when an operation or function is applied to an object of inappropriate type, e.g.
if you try to compute a square-root of a string value.
an
ValueError Raised when a built-in operation or function receives an argument with
inappropriate value e.g., int("z10") will raise ValueError.
ZeroDivisionError Raised when the second argument of a division or modulo operation is zero.

to be represented.
OverflowError Raised when the result of an arithmetic operation is too large

not found in the set of existing keys.


KeyError Raised when a mapping (dictionary) key is
AMDI E 24 Write the corresponding Python expressions for the following mathematical expressions :
() Ja' +b²+? (i) 2-yey +4y (i) p+
(r+s)*
(iv) (cosx/ tan x)+x
SOLUTION

() math.sqrt (a*a +b*b+C*) (ii) 2- y* math.exp(2*y) + 4*y


(ii) p+q/ math.pow((r +s), 4) (iv) (math.cos (x) / math.tan (x) ) +*
() math.fabs (math.exp(2) -x)
of
EXAMPLE 25 The radius of asphere is 7.5 metres. Write Python script to calculate its area and volume. (Area
asphere = nr Volume of asphere = 4nr°)
SOLUTION
import math
r=7.5
area = math.pi *r* r
volume = 4* math. pi * math. pow(r, 3)
print("Radius of the sphere : ",r, "metres")
square")
print ("Area of the sphere:", area, "units
cube")
print ("Volume of the sphere : ", volume, "units

Output:
Radius of the sphere: 7.5 metres
176.71458676442586 units square
Area of the sphere :
5301l.437602932776 units cube
Vo lume of the sphere:
using Heron's formula as
Atriangle has three sides a, b, c as 17, 23, 30. Calculate and display its area
s=2+b+c Area =s(s-a)(s-b)($-c)
2

Solution.
import math
a, b, c= 17, 23, 30
S= (a+b+c)/2
math.sqrt(s * (s-a) * (s-b) * (s-c))
area =
print("Sides of triangle:",a, b, c)
"units square")
print( "Area :", area,
Output :
23 30
sides of triangle: 17
194.42222095223582 units square
Area :
11. Write a Python progran calculate the anount payable if money has been lent on
Principal or money lent = P, Rate of interest = R% per annum and Time =T simple interest.
years.
Tlhen sinple interest (SI) =(Px Rx T)/ 100.
Amount payable = Principal + SI.
p. Rand T are gVen as mput to the program.
Ans.
P= float( input("Enter money lent:"))
R= float( input("Enter rate of interest:"))
T= float( input("Enter time in years:") )
SI = (P *R*T) / 100
amountpayable =P+ SI
print("Amount payable is : Rs.", amount_payable)
Sample Run :
Enter money lent: 7000
Enter rate of interest: 8.5
Enter time in years: 3.5
Amount payable is : Rs. 9082.5
MORNING" n time. Here 'n' timnes. Here 'n' is an intege
16. Write a program to repeat the string "GOOD
entered by the user.
Ans.
?"))
n= int (input ("How many times
print ("GOOD MORNING" * n)

Output :
HOw many times ? 3
MORNINGGOOD MORNING
GOOD MORNINGGOOD
calculated eethe mass (m)
cnergy (E) can be that mul
262 onHult
cuitalent program tccepts the mass
states that the stuared. Wrile a of
E-me 10n/s
20. The frmula
ca ahut 3x
spl of light
he
dctermines its enerxy.

Ans
Import math :"))
(input("Enter mass
m float
pow(10, 8)
C3"pow
#unit of
energy 1e e s
"Joule")
EmC("Eauivalent energy :", E,
orint ("Equ
Output :
Enter mass : 8.95 8.055e+17 Joule
Equivalent energy put upiright against a wall. Let ariables leneth and angBe store tse length ds
an i
ladder as it leans against lhe tval!, Write Prog
21. Presume that a
forms uith the ground values or leuol.
ladder ad the gncle tat it by tlhe ladder on the wall for the following
comute the height reached (6) 20 feet and 0
degrees
(a) 16 feet and 75 degrees feet and 80 degrees
degrees (d) 24
(c) 24 feet and 45 against the wall will form a
leaning
Solution. Since the ladder up to which a ladder reaches
can be
right-angled triangle, the height
calculated as : hlin
on the same.
Thus, our Python program is based
import math
ladder :"))
length float (input("Enter length of the
angle =float( input("Enter angle of leaning (in degrees):"))
ang radian =math.radians(angle) # convert degrees to radians
height length *math.sin(ang_radian)
print ("Ladder's height on the wall :", height)
Sample run :
Enter length of the ladder : 16
Enter angle of leaning (in degrees): 75
Ladder's height on the wal1 : 15.454813220625093
Enter length of the ladder : 20
Enter angle of leaning (in degrees) :0
Ladder's height the wal1 : 0.0

Enter length of the ladder : 24


Enter a
angle
g of leaning (in
Ladder's height on the degrees): 45
wall :
Enter length of the ladder
16.970562748477143
: 24
Enter angle of leaning (in
Ladder's height on the wall:degrees) : 80

23.63538607229299

You might also like