Skip to content
Advertisement

python printing correct line in program

I am taking a Python programming course with this question on strings:

phrase = "HULK MAD"
phrase = phrase.lower()
phrase = phrase.title()
cut_phrase = phrase[:5]
new_phrase = ""

for char in phrase[5:]:
    if char == "m":
        new_phrase = cut_phrase + "Hungry"
    elif char == "a":
        new_phrase = cut_phrase + "Angry"
    elif char == "d":
        new_phrase = cut_phrase + "Smash"
    print(new_phrase)

Which prints:

Hulk Angry
Hulk Smash

I’m getting tripped up on the questions:

What is the first, second, third, and fourth line printed by the code above? If a blank line is printed, write Blank. If there is no third line, write None.

The only question I got correct was the fourth line printing None. Would ALL lines first, second, third, and fourth all be None because there isn’t a Python print statement inside the 1st – 4th lines of code????

Advertisement

Answer

This is the output of that program:

(a blank string)
Hulk Angry
Hulk Smash

The question is asking about those lines of output, not about lines of code.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement