The cash register runs a program to print a different message at the bottom of a receipt on each day of the week. Which type of statement would be most effective for executing this program?
1. an If statement
2. an Elif statement
3. an Else statement
4. an If and Only If statement
Answers
Answer:
2.an Elif statement
Explanation:
There are 7 different days in the week.So we have to print 7 different messages by checking the day in the week.So here if statement can also help us but it is not much efficient.So next is Elif statement it is correct for our problem because it checks the condition and print the related message.So finally the answer is 2 that is an Elif statement.
Answer:
The correct option is (2) an elif statement
elif statement is used to check for multiple expressions.
If the condition of if block is false, it goes to the elif block and checks the condition, and so on.
If all the conditions are false then else block will execute.
In the case of elif, only one block will execute among several blocks.
In the above case, we need to print different messages according to the day of the week. Since we need seven different conditions because there are seven days in a week. Therefore we will make use of elif.