Ira, Jayla, and Kendra are all saying it would be better to move lines 22 and 24 to a single line executing print ('Code complete.') just before line 21. These three students have different reasons for their opinions. Their reasons are below. Do you think each of them is right, wrong, or somewhere in between? Explain your answer for each student. Ira: "It would be better to have a single print statement because that code is going to happen no matter what. The program will run slower by having it there twice." Jayla: "It would be better to have a single print statement because that code is going to happen no matter what. Later, if you want to change your program, you’re going to have to remember to change it in two places the way the code is now." Kendra: "It would be better to have a single print statement because it is going to happen no matter what. That program would take up less memory if you just wrote it once."

Answer :

MrRoyal

Missing Part of the Question

Here's the code segment, in question

21: if check == 2:

22: print('Code Complete')

23 else:

24 print('Code Complete')

25 print('Not all systems are ready')

Answer:

Ira, Jayla and Kendra are all right

Explanation:

1.

Ira thinks that wrting the same print statement in both conditions ( if and else) is not needed because the statement will be executed no matter the outcome of the conditions and would cause the program to run slower.

Ira is right and I agree; there is no need for extra code to be processed if the demand has to be executed and is not based on a condition. Basically, you don't have to write the same code twice when they serve the same purpose

2.

Jayla thinks using a single print statement because the code would definitely be executed no matter what and one might forget the other when there's a need to modify the code e.

Jayla is also right; Jayla's reason points to the fact that there's a need to simplify codes (when needed) and do away with bulky lines of codes. Changing a line and forgetting to change the other leads to an unintended expectation of a different output from the programmer.

3.

Kendra thinks It would be better to have a single print statement because it is going to happen no matter what. That program would take up less memory if you just wrote it once.

Kendra's reason is self explanatory; nevertheless I'll add my bit.

Repeating the same line of codes twice when not necessarily needed, takes up more memory.

Other Questions