Menu

Python Programming

Card 1 of 102 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
All 102 cards in this set
Which term describes the information that a program displays on the screen?
Output
What is meant by \n when it is used inside a print instruction?
It starts a new line when the code runs
What is the name for joining two pieces of text together in Python?
Concatenation
What is meant by quotation marks in Python?
Symbols that show where a piece of text starts and ends
What does the print() function do?
It shows the items inside its brackets on the screen
Which line of code correctly outputs the word hello?
print('hello')
What does print(12 + 13) output?
25
What does print('12' + '13') output?
1213
What is displayed by print('Hello\nWorld')?
Hello and World on separate lines
A variable called name holds the text John. What does print('My name is ' + name) display?
My name is John
A variable called score holds 4. What does print('Your score is', score) display?
Your score is 4
A student writes print = (temperature). What happens when the code runs?
Nothing is printed
A variable called message holds the text hello world. What does print(message) display?
Hello world
A student runs a program that contains only the line 12 + 13. What is displayed on the screen?
Nothing
A student wants their program to output the answer to 8 times 3. Which line should they write?
print(8 * 3)
What is meant by an identifier?
The name given to a variable in a program
Which term describes the rule that message and Message are treated as two different names in a program?
Case sensitive
What is meant by the value of a variable?
The data that is held inside a variable while the program runs
What is placed around a text value such as the word Hull when it is stored in a variable?
Quotation marks
A program contains the line city = 'Hull'. Which term describes the word city?
The identifier
What is a variable in a program?
A named space in memory that stores data
What does the equals sign do in the line temperature = 18?
It sets the value that the variable holds
Which of these could be used as an identifier in Python?
ScoreOne
A program contains score = 10 and then Score = 20. What is stored in the variable score?
10
What is stored in the variable a at the end of this program?
25
What is stored in temperature after the second line of this program runs?
19
Variables are often used to keep a score in a quiz. Why is a variable suitable for this?
Its value can be changed while the program runs
A program has the line name = 'Elizabeth'. Which line uses the value stored in the variable name?
print(name)
A programmer wants the variable temperature to store the number 18. Which line does this?
Temperature = 18
What is stored in the variable score at the end of this program?
9
What is meant by a data type in Python?
The kind of value that a piece of data is
Which term describes data that is written inside quotation marks in Python?
Text
What is meant by an integer?
A whole number that can be used in calculations
Which term describes joining two pieces of text together in Python?
Concatenation
What does the int() function do to a piece of text?
Turns the text into a whole number
What is the result of '12' + '13' in Python?
1213
Which line of code makes Python add the values together to give 90?
print(45 + 45)
What happens when this program runs?
The program stops with an error
What type of value does input() always store?
Text
A program stores a value with score = input('Score: '). The value must then be used in a calculation. What should be done?
Using int(score) so the value becomes a whole number
A program needs to store the number a user types as a whole number at the moment it is stored. Which line does this?
The line score = int(input('Score: '))
A program asks for the name of a town and stores the answer. Which line should be used?
The line town = input('Town: ')
This program stops with an error. Which change makes it print 175?
Removing the quotation marks from 55
A program stores score = input('Score: ') and then compares it with the number 50. Why must int() be used?
Because input() stores the score as text
A program stores a name with name = int(input('Name: ')). The user types Sam. What is the result?
The program stops with an error
The user types 8 when this program runs. What is the result?
10
What is meant by input in a Python program?
Data that a program receives from the user while it is running
Which term describes the text inside the brackets of input() that is shown to the user before they type?
Prompt
What is meant by a variable in a Python program?
A named store that holds a value so it can be used later
What is meant by a function in a Python program?
A named block of code that performs a job when it is called
Which term describes the pair of symbols that must surround the question inside input()?
Quotation marks
In the line name = input('What is your name? '), which part is the function that gets data from the user?
The word input
What happens to the user's answer if it is not stored in a variable?
The answer is lost and cannot be used later
Which line correctly asks the user for their name and keeps the answer?
Name = input('What is your name? ')
When is the text inside the brackets of input() shown on the screen?
Before the user types their answer
A program runs age = input('How old are you? ') and the user types 12. What does age hold?
The text 12
A programmer wants the user's score saved as a whole number. Which line should they use?
Score = int(input('What is the score? '))
Why do programmers often put a space at the end of the prompt text?
So the typed answer does not touch the question
The user types Sam when this program runs. What is shown?
The program shows Hello, Sam
A program asks for a name and an age and then prints both in one sentence. What must the programmer do with the two answers?
Store each answer in its own variable
A program sets score = 10 in its code. A second program uses score = input('What is the score? '). Why is the second program more useful?
It can use a different score each time it runs
A student writes name = input('What is your name? ) and runs the program. What is wrong with the line?
The prompt text is missing its closing quotation mark
What is the name for the way a program decides which blocks of code to run based on conditions?
Selection
What is meant by 'elif' in Python?
A keyword that checks another condition when earlier ones are not met
What is the name for the test on an if line that decides whether the indented code will run?
Condition
What is meant by 'else' in Python?
A keyword that runs its code when the if condition has not been met
What is the name for a decision that is placed inside another decision in a program?
Nested if
What is meant by 'indentation' in Python?
The spaces at the start of a line that show which block it is in
In a Python condition, what does the symbol != check?
Whether two values are different
What does the symbol <= mean in a Python condition?
Less than or equal to
In a Python condition, what does the symbol == check?
Whether two values are the same
What must come at the end of every if, elif and else line?
A colon
A program outputs Pass when the score is greater than 50 and Fail in every other case. What does it output for a score of 50?
Fail
A quiz prints Brilliant for a score above 75, Great for a score above 50 and Okay for a score above 25, otherwise Low. What is printed for a score of 80?
Brilliant
Why is int() used around a value typed by the user before it is compared with a number?
It converts the text typed in into a whole number
A program says Hello Elizabeth! only when the name typed in is Elizabeth. The user types elizabeth instead. What happens?
Nothing is printed because the text must match exactly
What happens to code written after an if and else block if it is not indented?
It runs whatever the result of the condition was
A nested if asks a second question only when the first answer is door. The user answers window instead. What happens next?
No second question is asked and nothing is printed
The condition int(age) >= 13 decides whether Teen is shown. Which ages show Teen?
13 and every age above 13
A pupil writes Else: on a line instead of else:. Why will the line not work?
Because if, elif and else must be in lowercase
A pupil wants two messages printed when a condition is met. How should the two print lines be written?
Both indented by the same amount under the if line
Why do most programs use selection?
So they can react differently depending on the data
A pupil writes an if line, then an else line, then an elif line. Why will this not work?
An elif line must come before the else line
A program has an if line and two elif lines but no else. What happens when none of the three conditions is met?
None of the blocks run and the program carries on
What is meant by a syntax error?
An error caused by a typo or a missing symbol, which makes the program crash
What is the name for the extra spaces or Tab at the start of a line of code that show it belongs inside an if statement?
Indentation
What is meant by a logic error?
An error where the program runs but gives the wrong result
When a program is tested, what is meant by the expected result?
The output the programmer wants the program to give
What happens when a program contains a syntax error?
The program crashes and does not run
A program runs without crashing but always shows the wrong message. Which type of error is this?
A logic error
This line should start an if statement but causes a syntax error: if score > 40. What is missing?
A colon at the end of the line
A line reads print('Hello world) and the program crashes. What is wrong with the line?
The closing quotation mark is missing
A student writes Print('Enter your name') and the program crashes. What is the mistake?
The function name must be written in lowercase
The line print(5 + 3 will not run. Which symbol is missing?
A closing bracket at the end
The code under an if line is not indented, so the program crashes. What is the fix?
Indent the line by pressing Tab at the start
The program is meant to print 'Low stock' when there are only a few apples, but it prints it when there are lots. Which change fixes the logic error?
Change the > symbol to <
This program crashes when it is run. Why?
The variable name is written differently on each line
Why should a programmer test a program with several different inputs?
To check it always gives the expected result
Why is finding and fixing errors an important part of programming?
Because every programmer makes mistakes that need to be fixed
This line causes a syntax error: 1score = 10. What is wrong with the line?
A variable name cannot begin with a number
A program has two mistakes: a missing colon after an if line, and a condition that uses < instead of >. Which statement is true?
The missing colon stops the program, the wrong symbol gives a wrong result
A program runs without crashing but gives the wrong result. What is the best way to find the mistake?
Read the code one line at a time and check each condition