Edexcel GCSE Computer Science 1CP2
Computational Thinking
Data
Computers
Networks
Issues and Impact
Problem Solving with Programming
Problem Solving with Programming
Keyboard input, screen output and CSV files
- 3 things to know
- Paper 2
Overview
input() and output, opening, reading, writing and closing CSV files, readline() and readlines(), splitting and stripping lines, and formatting output.
What you need to know
Answer each one before you reveal it.
How can Python read a CSV file line by line, and how do readline() and readlines() differ?
What does name = input("Name: ") do when it runs?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What does name = input("Name: ") do when it runs?
Model answer
The prompt Name: appears and the program waits for the user to type. The typed line is stored in name as a string.
- 2
How should a program respond when a user picks option 9 from a menu offering 1 to 3?
Model answer
The program should reject the choice with a clear message. The program should then ask again rather than crash or carry on.
- 3
Define a CSV file.
Model answer
A CSV file is a text file that separates its values with commas. Each line of the file usually holds one record.
- 4
How is a file opened for reading in Python?
Model answer
The call open("data.csv", "r") opens the file for reading. The call returns a file object that the program reads from.
- 5
What is the difference between opening a file with "w" and with "a"?
Model answer
The mode "w" creates the file or wipes an existing one before writing. The mode "a" adds to the end and keeps what is already there.
- 6
Explain why a file must be closed after use.
Model answer
The close() method finishes any writing and releases the file. Other programs, or later code, can then use the file safely.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Problem Solving with Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.