Wednesday, November 16, 2022

Strings and Variables 3 - Python Programming for Beginners Practice Exercise

Exercise 3:

Write a Python program that prompts for input and displays a cat "saying" what was provided by the user. Place the input provided by the user inside a speech bubble. Make the speech bubble expand or contract to fit around the input provided by the user.

Sample Output:


Solution:

  1. #!/usr/bin/env python3
  2.  
  3. text = input('What would you like the cat to say? ')
  4. text_length = len(text)
  5.  
  6. print(' {}'.format('_' * text_length))
  7. print(' < {} >'.format(text))
  8. print(' {}'.format('-' * text_length))
  9. print(' /')
  10. print(' /\_/\ /')
  11. print('( o.o )')
  12. print(' > ^ <')

No comments:

Post a Comment