BT NhiemVu 1
BT NhiemVu 1
HCM
KHOA CÔNG NGHỆ THÔNG TIN
BÀI TẬP
NHIỆM VỤ 1
PYTHON CƠ BẢN
Numbers
Exercises 1_1
1. Declare 5 as num_one and 4 as num_two
a) Add num_one and num_two and assign the value to a variable total
b) Subtract num_two from num_one and assign the value to a variable diff
c) Multiply num_two and num_one and assign the value to a variable
product
d) Divide num_one by num_two and assign the value to a variable division
e) Use modulus division to find num_two divided by num_one and assign
the value to a variable remainder
f) Calculate num_one to the power of num_two and assign the value to a
variable exp
g) Find floor division of num_one by num_two and assign the value to a
variable floor_division
2. The radius of a circle is 30 meters.
a) Calculate the area of a circle and assign the value to a variable name
of area_of_circle
b) Calculate the circumference of a circle and assign the value to a
variable name of circum_of_circle
c) Take radius as user input and calculate the area.
2
Operators
Exercises 1_2
1. Write a program that prompts the user to enter base and height of
the triangle and calculate an area of this triangle (area = 0.5 x b x h).
2. Write a script that prompts the user to enter side a, side b, and side c
of the triangle. Calculate the perimeter of the triangle (perimeter = a
+ b + c).
3. Get length and width of a rectangle using prompt. Calculate its area
(area = length x width) and perimeter (perimeter = 2 x (length +
width))
4. Get radius of a circle using prompt. Calculate the area (area = pi x r x
r) and circumference (c = 2 x pi x r) where pi = 3.14.
5. Calculate the slope, x-intercept and y-intercept of y = 2x -2
6. Slope is (m = y2-y1/x2-x1). Find the slope and Euclidean distance
between point (2, 2) and point (6,10)
7. Compare the slopes in tasks 8 and 9.
8. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x
values and figure out at what x value y is going to be 0.
9. Find the length of 'python' and 'dragon' and make a falsy comparison
statement. 3
Operators
Exercises 1_2_cont
10.Use and operator to check if 'on' is found in both
'python' and 'dragon'
11.I hope this course is not full of jargon. Use in operator to
check if jargon is in the sentence.
12.There is no 'on' in both dragon and python
13.Find the length of the text python and convert the value
to float and convert it to string
14.Even numbers are divisible by 2 and the remainder is
zero. How do you check if a number is even or not using
python?
15.Writs a script that prompts the user to enter hours and
rate per hour. Calculate pay of the person?
16.Write a script that prompts the user to enter number of
years. Calculate the number of seconds a person can
live. Assume a person can live hundred years 4
Python if...else Statement
Exercises 1_3