You are on page 1of 1

python

chapter two
Exercises
1. Write a program that will ask the user for their first
name.
The program should then concatenate the name
with a message, such as Hello Fred. How are you?
and output this string to the user.
2. Write a program that asks the user to enter two
real numbers and displays the product of these
two numbers to 2 decimal places, with user-
friendly messages.
3. Write a program to enter a temperature in degrees
Fahrenheit and display the equivalent temperature
in degrees Centigrade.
The formula for conversion is Centigrade =
(Fahrenheit - 32) * (5/9).
4. Write a program to convert a persons height in
inches into centimetres and their weight in stones
into kilograms.
1 inch - 2.54 cm and 1 stone - 6.364 kg.
5. Write a program to enter the length, width and
depth at the deepest and shallowest ends of a
rectangular swimming pool.
Calculate the volume of water required to fill the
pool, and display this volume.
6. Write a program to enter the length and width of a
rectangular-shaped garden. Calculate the area of
the garden and the cost of turfing a lawn if a 1m
border is around the perimeter of the garden.
Assume the cost of turf is 10 per square metre.
Display the result of these calculations.
Syntax
!"#$%&'(
converts the string value 5 to an integer.
)*+,#$%&-.'(
converts the string value 5.6 to a float.
/#0$123"#(
converts the value stored in myInt to a
string.
0+4"5$126*+,#78(
rounds the float value to three decimal
places.
Vocabulary
52",1!9 #2;!"<
the data type of a variable is determined
and checked for correct usage during
execution.
9+"9,#=",#=
the process of joining together copies of
two or more text strings without any spaces
in between.
!"#=<=0
data type that stores whole numbers.
)*+,#
data type that stores decimal numbers.
/#0!"<
data type that stores one or more text
characters.
>++*=,"
data type that stores TRUE or FALSE.
+05!",* 5,#, #2;=/
an ordered set of values: integer and
boolean are examples.
/!1;*= 5,#, #2;=/
simple types include ordinal types and float.

You might also like