ItP 2 - User Input Flashcards

1
Q

We often want to ask the user for information. One to do this is the

A

input () function in Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The input function takes a string which will be used as … it then returns… - (2)

A

the “prompt” to the user.

It then returns what the user typed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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’

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What will be output of code if my input is zebra?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You can use the input() function to get input from the user.

This input is initially

A

a string, but you can convert it to an integer (or other data types) using conversion functions like int()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ‘int()’ function do in Python?

A

function is used to convert a given value to an integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What will be output of this code if my input is Gta?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Alter the code so that

Print out: the name, the number and the number doubled (times by 2).

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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:

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

3 main collections of data or data structures in Python are - (3)

A
  1. Lists
  2. Tuples
  3. Dictionaries
How well did you know this?
1
Not at all
2
3
4
5
Perfectly