Computer Science
Grade 6
20 min
Collecting Data
Collecting Data
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define 'user input' and explain its role in collecting data.
Write a line of code to ask a user a question and get their response.
Store user input into a variable.
Collect at least two different data types (string and integer) from a user.
Create a simple program that collects multiple pieces of related data to form a small data set.
Explain why clear prompts are important for collecting accurate data.
Have you ever entered your name to start a new video game or answered a poll online? 🎮 You were giving the computer data!
In this lesson, we'll learn how to make our computer programs ask questions and listen for answers. This is the first and most important step in data analysis: collecting the data we want to explore. We'll learn ho...
2
Key Concepts & Vocabulary
TermDefinitionExample
DataInformation that can be stored and used by a computer. It can be text, numbers, or other types of facts.Your name ('Sarah'), your age (11), or your favorite color ('blue') are all pieces of data.
User InputData that a person (the user) gives to a computer program while it's running.Typing your name into a text box and pressing Enter.
PromptA message the computer shows the user to tell them what kind of information to enter.The question 'What is your name?' that appears on the screen.
VariableA container in code used to store a single piece of data. It has a name that you can use to get the data back later.In `playerName = 'Alex'`, the variable is `playerName` and it holds the data 'Alex'.
Data SetA collection...
3
Core Syntax & Patterns
Collecting Text (String) Input
variable_name = input("Your question for the user")
Use this pattern to ask the user a question and store their typed answer as text (a string) in a variable.
Collecting Whole Number (Integer) Input
variable_name = int(input("Your question for the user"))
Use this pattern when you need a whole number from the user. The `input()` part gets the text, and the `int()` part converts that text into a number you can do math with.
Using the Collected Data
print("Some text", variable_name)
After you store data in a variable, you can use the variable's name to print it, use it in a calculation, or combine it with other text.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
You are building a program to recommend a pet. It first collects the user's age (an integer) and then asks if they have a yard (a boolean). The program then suggests 'dog' or 'hamster'. This entire process is an example of...
A.Creating biased data
B.Storing data in a list
C.Collecting data from a sensor
D.Using collected data to make a programmed decision
Challenging
A city wants to decide where to build a new playground. To be fair, which data collection plan is the best and least biased?
A.Survey only families who live in the biggest houses
B.Use sensor data to find which street corner is the busiest
C.Survey a random sample of families from all neighborhoods in the city
D.Ask the city council members where their children would like a park
Challenging
A programmer is creating a smart speaker that activates when it hears the phrase 'Hey Computer'. To do this, it must always be listening. What is the most important ethical problem with collecting audio data this way?
A.The device might accidentally record and store private conversations
B.The device might not hear the command in a noisy room
C.Storing audio data takes up a lot of computer memory
D.The user might say the activation phrase too quietly
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free