Python_A5
Python_A5
To complete the task, aside from being logical, you also need to know more about Python.
Follow the instructions to write code to learn about strings, integers, and variables.
What is a String?
A string is text. It can be a word, phrase, or sentence. In Python, str is short for string.
To learn about strings, type each line of code and then press ENTER to study the output.
2. A string must have brackets and quotes around it:
>>> print('a string is text')
If you want both, you need to put a slash before the apostrophe:
>>> print('she said "let\'s start now"')
Be logical. Study the above code to determine how to complete each task:
it's fun I said "wow" I said "wow, it's fun"
What is an Integer?
An integer is a whole number such as 10 or 42. In Python, int is short for integer.
To learn about integers, type each line of code and then press ENTER to study the output.
3. An integer must have brackets around it:
>>> print(5)
A string cannot
5
be calculated
but an integer
An integer can be used to calculate values: can.
>>> print(6+4)
10
Think logically! Study the above code to determine how to complete each task:
show 10 calculate 3+2 show the equation 3+2=
What is a Variable?
A variable stores a value that can change. It can be text, a number, or a list of items.
To learn about variables, type each line of code and then press ENTER to study the output.
4. A variable has two parts – name and value:
>>> name=('value')
>>> print(name)
value
The print command lets you show
the stored value of the variable.
A variable can store a string or integer. Think logically! Show the value using print:
weather=('sunny') mood=('happy') count=(5)
Sometimes the programmer will input a value for a variable. However, other times the user can
input a value. This is done using the input command.
Type in an answer.
The input can be used to have the program talk to the user:
>>> print('I also like', food)
I also like pizza
Think logically! Study the above code to determine how to ask each question:
What music do you like? What is your age? Do you like sports?
Name a Variable
A variable name must be meaningful. It should describe its purpose. There are rules you must
follow when assigning a variable name. To learn them, type each line of code and then press
ENTER. Does the variable name follow the rules, or do you get an error?
6. A variable name must start with a letter or underscore, but not a symbol or number.
Put a checkmark ✓ beside the variable names that work: