Input
Part of the Fundamentals section of Coddy's Python journey — lesson 26 of 77.
As of now we stored values that we thought about in variables. Programs usually don't work this way. We receive values from an outer source, a user for example.
To get input from a user or the system we need to write:
var = input()This will store the input in the variable var.
The input is always of type string. For example, if the input is 56 then
varwill hold the string"56".
Challenge
BeginnerWrite a program that get input from the user (their name), and then outputs Hello, followed by a space and the user's inputted name.
For example, if the user inputs Bob, the expected output is Hello, Bob.
You will need to:
- Use
input()to get input from the user. - Store the input in a variable.
- Print
Hello,and the stored variable in the end (add a space after the comma).
Cheat sheet
To get input from a user:
var = input()The input is always stored as a string, even for numbers.
To print a greeting with the input:
name = input()
print("Hello, " + name)Try it yourself
# Write code hereThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2