Output to display
Outputting to the Display
Output is how a program communicates results back to the user. Without output, a program could perform calculations or process data but the user would never see the result. Displaying text, numbers, and the contents of variables are the three most common forms of output at this stage.
| Language | Output a single value | Output without a newline |
|---|---|---|
| Python | print(value) | print(value, end="") |
| VB.NET | Console.WriteLine(value) | Console.Write(value) |
| C# | Console.WriteLine(value); | Console.Write(value); |
In all three languages, the standard output command adds a newline after printing - meaning the next output appears on the line below. Use the "without newline" variant when you want two pieces of output to appear on the same line.
Worked Examples
The simplest output is a fixed text message - a string literal written directly inside the output command. The text must be placed inside quotation marks.
AQA pseudocode: OUTPUT "Welcome to the quiz!"
# Python -- print a fixed text message
print("Welcome to the quiz!")
print("Good luck!")
' VB.NET -- print a fixed text message
Console.WriteLine("Welcome to the quiz!")
Console.WriteLine("Good luck!")
// C# -- print a fixed text message
Console.WriteLine("Welcome to the quiz!");
Console.WriteLine("Good luck!");
Passing a variable to the output command prints whatever value is currently stored in that variable - without quotation marks around the variable name. Quotation marks would print the name itself as text rather than its value.
AQA pseudocode: OUTPUT score
# Python -- print the value stored in a variable
score = 42
print(score) # prints: 42
print("score") # prints: score (the word, NOT the value!)
' VB.NET -- print the value stored in a variable
Dim score As Integer = 42
Console.WriteLine(score) ' prints: 42
Console.WriteLine("score") ' prints: score (the word, NOT the value!)
// C# -- print the value stored in a variable
int score = 42;
Console.WriteLine(score); // prints: 42
Console.WriteLine("score"); // prints: score (the word, NOT the value!)
Sometimes you need to display a label and a value together on one line. Python's print() accepts multiple arguments separated by commas - it prints each one with a space between them. In VB.NET and C#, use Console.Write() for the label (no newline) then Console.WriteLine() for the value (with newline).
AQA pseudocode: OUTPUT "Hello", username
# Python -- print() accepts multiple comma-separated arguments
username = "Alice"
age = 15
print("Hello", username) # prints: Hello Alice
print("Your age is", age) # prints: Your age is 15
print("Name:", username, "Age:", age) # prints: Name: Alice Age: 15
' VB.NET -- Console.Write() prints without a newline; Console.WriteLine() ends the line
Dim username As String = "Alice"
Dim age As Integer = 15
Console.Write("Hello ") ' no newline -- stays on same line
Console.WriteLine(username) ' prints: Hello Alice
Console.Write("Your age is ")
Console.WriteLine(age) ' prints: Your age is 15
// C# -- Console.Write() prints without a newline; Console.WriteLine() ends the line
string username = "Alice";
int age = 15;
Console.Write("Hello "); // no newline -- stays on same line
Console.WriteLine(username); // prints: Hello Alice
Console.Write("Your age is ");
Console.WriteLine(age); // prints: Your age is 15
Key Takeaways
- Use
print()in Python andConsole.WriteLine()in VB.NET and C# to display output on a new line. - To output a fixed message, place the text inside quotation marks. To output a variable's value, pass the variable name without quotation marks.
- Python's
print()accepts multiple comma-separated arguments and inserts a space between them automatically. - In VB.NET and C#, use
Console.Write()to output without a newline, thenConsole.WriteLine()for the final piece on that line.