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

Python Practical 03

The document contains examples of Python code snippets for: 1) Validating identifier names in Python based on keywords and special characters. 2) Converting between units like meters to inches, miles to kilometers, and calculating area, hypotenuse, and capacity. 3) Examples of user input in Python to calculate ratios, area, interest, and time to fill bottles.

Uploaded by

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

Python Practical 03

The document contains examples of Python code snippets for: 1) Validating identifier names in Python based on keywords and special characters. 2) Converting between units like meters to inches, miles to kilometers, and calculating area, hypotenuse, and capacity. 3) Examples of user input in Python to calculate ratios, area, interest, and time to fill bottles.

Uploaded by

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

Cit01-22ug3-638-practical03

No Identifier Usage Justification


I) -continue Not legal Key words

ii) 5boys illegal Can’t start with digit

iii) Boys and Girls illegal Can’t put space


iv) _my_stuff legal recommended

v) !Oh illegal symbol


vi) Jzcpriwqkfvc legal Not meaningful

vii) B2b legal Not meaningful

viii) pass illegal Key words


ix) Number_of_birds=10 legal meaningful

x) sum legal meaningful

02. a) >> length_in_meters=10

>>> length_in_inches=10*39.37

>>> print(f'The length of the cablerounded={length_in_inches:.2f}inches')

The length of the cablerounded=393.70inches

b) >>> x=miles_in_kilometers=5/8

>>> y=miles_per_hour=x*60

>>> print(f'miles per hour={y}mph') ... miles per hour=37.5mph

c) >>> opposite=1.73 ..

. >>> adjacent=3.5 ...

>>> hypotenuse=(1.73**2+3.5**2)**0.5

... >>> print(f'hypotenuse is {hypotenuse:.5}cm')

... hypotenuse is 3.9042cm

d) >>> width=2.65
Cit01-22ug3-638-practical03
... >>> length=2.65

... >>> area=width*length

... >>> print(f'Area is {area}cm\u00b2')

... Area is 7.0225cm²

03) a)length=float(input(“Enterthe lengthof the cool box in meters:”))

Breadth=float(input(“Enter the breadth of the cool box in meters:”))

Height=float(input(“Enter the height of the cool boxin meters:”))

Capacity=length*breadth*higth

Print(f”The capacity of the cool box is {capacity:.2f}m\u00B3”)

B) Boys=int(input(“Enter the number of boys in the class :”))

Girls=int(input(“Enterthe numer of the girls in the class:”))

Total=boys+gilrls

Girls_percentage=(girsl/total)*100

Boys percentage=(boys/total)*100

Print(f”The ratio girls to boys is {girls_percentage:.2f}%:{boys _percentage:.2f}%”)

c) a=float (input(“Enter the area of square shaperoom(ft\u00b2)=”))

print(f’Length of a side ={**0.5}ft”)

d) a=float(input(“Enter your amount=*))

b=float(input(“Annul rate (%)=”))

c=float(input(“period=”))

print(f’Annually interest is ={a/100*b}LKR’)

print(f’interest for one period={(a/100*b)/c}LKR)

E) T=10

X=4

X=20
Cit01-22ug3-638-practical03
Hours=t/x/*y/60

Hours

0.33333

Print(‘The numberof hourto fill{y}bottles={hours:.2f}’)

The number of hours to fill 20 bottles0.83

You might also like