Module 3 Flashcards
What is one of the essential features of computer programs?
Their ability to make decisions.
What is an if statement?
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.
compound statements
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
statement block
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
why should you avoid duplicate codes?
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.