Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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????

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading