38
1 The First Few Steps
Filename: volume3cubes.py.
Exercise 1.5: Average of Integers
Write a program that stores the sum 1 + 2 + 3 + 4 + 5 in one variable and then
creates another variable with the average of these five numbers. Print the average to
the screen and check that the result is correct.
Filename: average_int.py.
Exercise 1.6: Formatted Print to Screen
Write a program that defines two variables as x = pi and y = 2. Then let the
program compute the product z of these two variables and print the result to the
screen as
Multiplying 3.14159 and 2 gives 6.283
Filename: formatted_print.py.
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0
International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing,
adaptation, distribution and reproduction in any medium or format, as long as you give appropriate
credit to the original author(s) and the source, provide a link to the Creative Commons licence and
indicate if changes were made.
The images or other third party material in this chapter are included in the chapter’s Creative
Commons licence, unless indicated otherwise in a credit line to the material. If material is not
included in the chapter’s Creative Commons licence and your intended use is not permitted by
statutory regulation or exceeds the permitted use, you will need to obtain permission directly from
the copyright holder.
Précédent

- 60/350

Suivant