Learn Input and Output
Learn Input and Output
Learn Input and Output
being
recorded
APPLY TASK ANSWER
WEEK 3
Starter
What code word would you need to ask the user to enter their name?
What code word would you need to ask the user to enter their name?
input
So far, you’ve been writing code that simply performs an action or calculation.
However, for programs to be truly useful, people need to be able to interact with them
when they are running.
The = is the
assignment symbol. This is the function.
It means ‘is given the Be careful with
value of’. You’ve spelling and use
used it before. lower case letters.
Input() and data types
This is fine if you’re just working with text, but what if you want to work with other data types?
Type conversion is the answer. Python contains functions that allow you to change the data type of the
variable.
Type conversion
In Python you can use the <string>.format() function to modify the look of a string when it is output.
The format function allows programmers to substitute variables into strings and add positional formatting.
It makes output more readable and user friendly .
Recall that the print() function displays one line of text to the screen (and also starts a new line).
Combined, these two functions can produce rows of output text that are formatted in the layout needed.
<string>.format() usage
Format works by putting placeholders into a string, defined by { }, and calling the <string>.format()
function.
Outputs:
You can do this with other data types and with multiple placeholders, like so:
Outputs:
<string>.format() usage
You can also specify which element you want to include in the place holder using an index value.
You can also add variable names to the items in the format function so that these are used in the
placeholder, like so:
You can also specify the data type of a value, like so:
Limit to two
decimal places
Let’s look closer at this:
Convert to float
Selects first
item in format
Plenary
Use the following summary and video link to make notes for your Apply task.
https://student.craigndave.org/videos/gcse-edexcel-topic-6b-user-input-and-display-output
Plenary
Use the following summary and video link to make notes for your Apply task.
https://student.craigndave.org/videos/gcse-edexcel-topic-6b-formatting-and-customising-string-output
Syllabus
APPLY TASK
Check your ‘to do’ list
for your Apply task
Deadline 1 week
Lesson complete!
See you next lesson