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

Lab 01 - Lab Exercise

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

Lab 01 - Lab Exercise

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

Computing

General Program Lab 01: Exercise GP106

Exercise
01. Basics
1. Evaluate the following expressions yourself (and then use Python terminal to check them).

(e) 2 ∗ 3 + 4
2 22×3
(a) 32 (c) 4+3
2 2 2(2×3) 2
(b) ( 3 ) (d) 4+3 (f) 23

2. Determine the values of the following logical expressions before trying them out in Python terminal.

(a) 3 > 2 (c) 4 < 3 + 1 (e) 5 & 3 < 5


(b) –4 < –3 (d) 3 >= 2 | 5 == 6

3. Write relational expressions to check the following situations and verify whether they are correct:

(a) Variable x lies between -10.0 and 10.0


(b) The sum of variables x and y is equal to the value of variable z
(c) Variable x that lies outside the range -10.0 and 10.0
(d) Variable x is a positive number which is smaller than 10.0

02. Python Scripts


1. Write a Python script (name it Lab01A.py) to request the user to enter his name and age and display the
details in the following format. Remember to use comments in your scripts and appropriate input and
output statements.
1 Enter your det ail s
2 -------------------
3 First name : Sa ma n Last
4 name : Dasanayaka Age :
5 25
6 Hi ! I am Sa man D as a n a y ak a and I am 25 years old .

2. Write a Python script (name it Lab01B.py) to calculate the volume of a cone. Request the user to enter
the radius (r) and the height (h) of the cone and display the volume in the following format. [Hints: (a)
The volume (V ) of a cone can be calculated using V = 13πr2h (b) use π as 3.14]

1 Volume of a co ne
2 ----------------
3 Enter radius : 7
4 Enter height : 10
5 The volu me of the cone is 513.127

3. In Civil Engineering, the vertical stress under the centre of a loaded circular area is given by the formula
given below.

Write a Python script (Lab01C.py) to get the user input for q, r and z and output the value for s. Use
appropriate formatting options to display the answer to the user.
Department of Computer Engineering, University of Peradeniya 1
Computing
General Program Lab 01: Exercise GP106

Important
Copying someone else’s codes (including your group mate’s) or showing your source codes to anyone else will
earn you zero mark for the whole lab exercise.

Department of Computer Engineering, University of Peradeniya 2

You might also like