Introduction To Python - Worksheet
Introduction To Python - Worksheet
IDLE has two main window types, the Shell window and the Editor window. It
is possible to have multiple editor windows simultaneously. The window that
appears when you first run IDLE is called the interactive shell. A shell is a
program that lets you type instructions into the computer.
The Python shell lets you type Python instructions, and the shell sends these
instructions to software called the Python interpreter to perform. We can type
Python instructions into the shell and, because the shell is interactive, the
computer will read our instructions and respond in some way. (Ideally in a way
that we expect but that will depend on whether we write the correct
instructions.)
TASK 1 ARITHMETIC
CALCULATIONS
Type the below expression in IDLE and press
enter:
2+2
Write down the response from the computer below:
+ pears
print myBag
To show what is currently being stored in a Variable we need to
use the PRINT command which will print the data (on to the
computer screen)
my_int=7
my_float=1.23
my_bool=True
A boolean is like a light switch. It can only have two values. Just
like a light switch can only be on or off, a boolean can only be
True or False.
What do you
think is
happening
print myName
print myName [0]
print myName [4]
Multi-Line Comments
The # sign will only comment out a single line. While you could
write a multi-line comment, starting each line with #, that can be
a pain.
Write a comment against each line of code. Tip always start with
the #.
my_variable =42
my_bag = 7
(replace
Follow the instruction (and press Enter). Make sure the typing cursor is in the Shell
window, at the end of this line. After you type your response, you can see that the
program has taken in the line you typed. That is what the built-in
function input does. First it prints the string you give as a parameter (in this
case 'Enter your name: '), and then it waits for a line to be typed in, and returns
the string of characters you typed.
The parameter inside the parentheses after input is important. It is a prompt,
prompting you that keyboard input is expected at that point, and hopefully indicating
what is being requested. Without the prompt, the user would not know what was
happening, and the computer would just sit there waiting!
I cant
do this
I can do
this with
some
I can
do this
on my
help
own