Console input and output
Reading from the keyboard, printing, converting an input, formatting an output (separator, line ending, number of decimals) and checking an input with a loop.
- 27 cards
- 3 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
A few cards from the deck
Standard input: what is it?
Show the answer
The stream a program reads its data from, connected by default to the console keyboard.
In Python,
input()reads a line from this stream and always returns it as a string, even if the user types a number.What does this program print?
```python
print('a', 'b', sep='-', end='!')
print(f'{3.14159:.2f}')`a-b!3.14a b!3.14a-b!3.14159a-b3.14
Show the answer
a-b!3.14sep='-'puts a hyphen betweenaandb, andend='!'replaces the line break: the secondprintcontinues on the same line..2fkeeps two decimals.In Python, whatever value the user types, the input function always returns a value of type ….
Show the answer
In Python, whatever value the user types, the input function always returns a value of type string.
input()guesses nothing: typing7gives'7', not7. The program must convert withint()orfloat().Standard output: what is it?
Show the answer
The stream a program writes its results to, shown in the console by default.
printwrites the text of the values to it, then by default a line break: the program shows only what it was told to write, nothing more.The user types 21. What does this program print?
```python
n = input()
print(n * 2)`422121TypeError21 21
Show the answer
2121nis the string'21':*repeats it twice. You neededint(input())to get42.