CompSci Autumn 2022/23 Python Flashcards

1
Q

1.1 What is input?

A

Input is where the user enters data. This could be the user typing data in.

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

1.2 What is output?

A

Output is where the program shows the user data. This could be a message on screen.

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

1.3 How do you output the message “Hello world”?

A

print(“Hello world”)

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

1.4 How do you let a user type in data?

A

age = datatype(input(“Enter age:”)

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

2.1 What is a variable?

A

In a computer program, a variable is used to store data.

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

2.2 How do you make the program store the user’s input?

A

name = datatype(input(“Enter name:”) will store the user’s input in a variable called ‘name’.

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

2.3 How do you output the contents of a variable?

A

print(name) will output the data held in the variable ‘name’.

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

2.4 int data type

A

Integer – stores whole numbers

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

2.5 str data type

A

String – can store a sequence of characters

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

2.6 float data type

A

Can store decimal values e.g. 3.5

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

2.7 bool data type

A

Can store a True or False value only.

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

3.1 What is selection?

A

Selection is where a program checks a condition, and the program responds accordingly.

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

3.2 What is a condition?

A

The condition is an expression that will result in a True or False value e.g. 1 = 2 will result in False.

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

3.3 Indentation

A

Refers to space at the beginning of a code line. In Python indentation is used to indicate a block of code.

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

3.4 How would you make a program show “Well done” if the variable score is above 10?

A

if score > 10: print (“Well done”)

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

3.5 What does the command “elif” do?

A

Allows additional conditions to be checked.

17
Q

3.6 What does “else” do?

A

This tells the program what to do if none of the conditions are True.

18
Q

4.1 What is iteration?

A

Iteration repeats a sequence of code instructions.

19
Q

4.2 What are the two types of iteration?

A

Definite iteration (count controlled) and indefinite iteration (condition controlled).

20
Q

4.3 What is definite iteration?

A

Definite iteration repeats lines of code a specific number of times, usually using a FOR loop.

21
Q

4.4 How would you make the program repeat code 5 times?

A

for i in range (6): code to be repeated

22
Q

4.5 What is indefinite iteration?

A

Indefinite iteration repeats lines of code until a condition is no longer met, usually with a WHILE loop.

23
Q

4.6 How would you make the program repeat while lives are greater than 0?

A

While lives > 0: code to be repeated