ItP 2 - User Input Flashcards
We often want to ask the user for information. One to do this is the
input () function in Python
The input function takes a string which will be used as … it then returns… - (2)
the “prompt” to the user.
It then returns what the user typed.
Write a code that takes user’s input of a word and stores into variable ‘data’
Then print type of ‘data’ variable
Then print contents of variable ‘data’
What will be output of code if my input is zebra?
You can use the input() function to get input from the user.
This input is initially
a string, but you can convert it to an integer (or other data types) using conversion functions like int()
What does ‘int()’ function do in Python?
function is used to convert a given value to an integer.
Example:
can also get numbers using input. They start as strings but then, if you are lucky, Python can convert them to int
What will be the output of this code?
What will be output of this code if my input is Gta?
Alter the code so that
Print out: the name, the number and the number doubled (times by 2).
Coding exericse:
Write a script which inputs two numbers. The first should be a number to count from, the second a number to count to. Once the user has input the numbers, you should print - using a loop - all of the numbers between the starting and ending number (inclusive; think carefully about this), one per line.
An example run of the program might look like this:
3 main collections of data or data structures in Python are - (3)
- Lists
- Tuples
- Dictionaries