Module 3 Flashcards

1
Q

What is one of the essential features of computer programs?

A

Their ability to make decisions.

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

What is an if statement?

A

An if statement allows a program to carry out different actions depending on the nature of the data to be processed

An if statement is like a fork in the road. Depending upon a decision, different parts of the program are executed.

Ex:

temperature has a value of 88

if temperature > 90:
print(“It is”)
else:
print(“It is not”)
print (“a hot day.”)

Prints:
It is not
a hot day.

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

compound statements

A

consist of a header and a statement block.

A statement construct that consists of a header and statement block. The header ends with a colon (:)

Ex:

temperature has a value of 88

if temperature > 90:
print(“It is”)
else:
print(“It is not”)

’ if temperature > 90: ‘ & ‘ else: ‘ are compound statements in this example

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

statement block

A

A group of one or more statements, all of which are indented to the same indentation level.

Ex:

temperature has a value of 88

if temperature > 90:
print(“It is”)
else:
print(“It is not”)

’ print(“It is”) ‘ & ‘ print(“It is not”) ‘ are statement blocks in this example

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

why should you avoid duplicate codes?

A

Although duplicate codes are not necessarily incorrect, it will complicate the code, thus use 1 line of code to avoid complicating codes.

Especially important when programs are maintained for a long time.

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