In this task, you will get more practice writing, evaluating, and assigning expressions to variables in Python. In particular, we will explore lists and strings. Open IDLE and interact with the terminal to complete the following steps:
a
, 8 to b
a
plus b
to c
and the value of a
minus b
to d
a
plus b
plus b
to e
a
plus b
plus a
plus b
times b
to c
c
plus a
, then divided by d
, to b
b
to the power 5 to d
b
divided by a
to c
a
, b
, c
, d
var
is a variable storing a string, what does len(var)
do?[2,5,9]
to a variable called myList
. Then
myList
.myList
? (Hint: Look at part (f) of the previous question.)"Hong Kong Polytechnic University"
to a variable called myU
. Then:
myU.split()
. What is the output? What does split()
do?
myU.split()
to the variable myWords
.
t
from myWords
(Note: there are two ways of doing this.)
PolyU
from myWords
myU
?
In this task, you will get some practice with writing programs and running them in Python.
Save As
) and open it in IDLE.Run
in the menu, and then Run Module
. Alternatively, you can just hit F5File... new File
. A new (blank) window should pop up. rmb
exchange
rmb
and exchange
. Store the answer in hkd
hkd
ACT2-1-2.py
. This is my first program.
#
at the beginning of that line (so that it will be # This is my first program
.) Save your program and run it again. What happens now?#
character?