Python Strings Homework - CTRL Zombies


Python Popcorn Hack

Write a program that:

  1. Creates two string variables: | name = "Your Name" | color = "Favorite Color" |

  2. Prints the sentence: Hello Alex, your favorite color is blue!

  3. Then prints the same sentence, but in all uppercase letters.

name = "Alex"           
color = "blue"            

sentence = f"Hello {name}, your favorite color is {color}!"
print(sentence)

print(sentence.upper())
Hello Alex, your favorite color is blue!
HELLO ALEX, YOUR FAVORITE COLOR IS BLUE!

Python Strings Homework

Your program should:
  1. Remove the extra spaces at the beginning and end.

  2. Capitalize only the first letter of the sentence.

  3. Replace the word “python” with “Python”.

  4. Print the final result.

  5. Also print how many characters the cleaned-up sentence has.

Hint:

Your program should be using these commands:

  • .strip()

  • .capitalize()

  • .replace()

  • len()

# Example
sentence = "   rock music is loud   "

cleaned = sentence.strip()

capitalized = cleaned.capitalize()

fixed = capitalized.replace("Rock", "Jazz")

print(fixed)            
print(len(fixed))       

Jazz music is loud
18
sentence = "   python strings are powerful   "

cleaned = sentence.strip()
capitalized = cleaned.capitalize()

final_sentence = capitalized.replace("python", "Python")

print(final_sentence)

print(len(final_sentence))

Python strings are powerful
27