Professional Documents
Culture Documents
Fragments of code that produce or calculate new data 2.7 Example Program: Future Value – completed in IDLE
values are called expressions. The simplest kind is a
2.9 EXCERCISES
literal.
Evaluation – process of turning an expression into an Review Questions: True or False
underlying data type.
1. False
2.4 Output Statements 2. True
3. False
Information can be displayed on screen using Python’s 4. True
built in function ‘print’. 5. True
Like other languages, Python has precise set of rules for 6. True
the syntax (form) and semantics(meaning) of each 7. True
statement. 8. False
Print(“The answer is “, end=” “)???? 9. True
10. False
2.5 Assignment Statements
Multiple Choice
2.5.1 Simple Assignment
1. C – Fee Setting
Form is <variable> = <expr> eg. X=5,
2. A
Fahrenheit = 9/5*Celsius+32
3. D – Specification
Process of automatic memory management is
4. C
called garbage collection.
5. B
2.5.2 Assignment Input 6. D – Assignment statements: Fragments of code that
produce or calculate new data values.
Purpose of input statement is to get 7. B
information from user of program and store it 8. D
into variable 9. B : variable-as-box – most accurate model of assignment
in python???
10. D
Discussion
2. #File: chaos.py
#A simple program illustrating chaotic behaviour.
def main():
print("This program illustrates a chaotic function.")
x = eval(input("Enter a number between 0
and 1 : "))
for i in range(10):
x = 3.9*x*(1-x)
print(x)
main()
3. Definite loop – executes a known number of times,
python for statement is a definite loop that iterates
through a sequence of values, a python ‘list’ if often
used in a for loop to provide a sequence of values for
the loop. Counted Loop – loop designed specifically for
the purpose of repeating some portion of the program a
specific number of times, created by using the built in
range function to produce a suitably sized list of
number. For loop – python built in function.
4. Show the output from the following fragments.
5. It is important to see how the program will work (IPO)
prior to coding.
6. Python ‘print’ function supports other keyword
parameters besides ‘end’ like ‘sep’ – the separator used
between multiple values when printing. ?????