0% found this document useful (0 votes)
23 views1 page

Coding Projects in Python (Dragged) 4

Uploaded by

Hayley Kelsey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Coding Projects in Python (Dragged) 4

Uploaded by

Hayley Kelsey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

VA R I A B L E S 25

LINGO
Integers and floats
In coding, whole numbers are called “integers”,
while numbers with a decimal point in them
are known as “floats”. Programs usually count
things using integers. Floats are more often
used for measurements. 0.5 sheep
1 sheep (an integer) (a float)

Using numbers Symbol Meaning


Variables can be used to store numbers and do sums. + add
You can use them with symbols to do calculations, – subtract
just like you do in maths. Some of these symbols will * multiply
be familiar, but watch out for the symbols meaning / divide
“multiply” and “divide”—they’re slightly different
from the ones you use in class. Some of the Python math symbols

Create a new variable, x, and give it the value 6.

1 A simple calculation
Type this code in a shell window. It uses >>> x = 6
numbers stored in two variables, named x >>> y = x * 7
and y, to carry out a simple multiplication.
>>> print(y)
Hit the enter/return key to get the answer.
42

Print the Multiply x by 7 and


value of y. store the result in y.
The result of the calculation
Change the value of x.

2 Change a value
To change the value of a variable, you just >>> x = 10
assign a new value to it. In your code, change >>> print(y)
the value of x to 10 and run the calculation
42
again. What do you expect the result to be?

The result hasn’t changed;


next we’ll find out why. Update the value of y.

3 Update the value


The value of y needs to be updated to get the >>> x = 10
correct result. Type these lines. Now the code >>> y = x * 7
assigns the new value to y after x has been
>>> print(y)
changed. If you update the value of one
variable in your own programs, always check 70
to see if you need to update any others.

You might also like