Skip to content

Instantly share code, notes, and snippets.

@thambaru
Created December 27, 2023 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thambaru/4d30c4d8a62882a2ca613da6b7495e0f to your computer and use it in GitHub Desktop.
Save thambaru/4d30c4d8a62882a2ca613da6b7495e0f to your computer and use it in GitHub Desktop.
Python program to print "Twinkle Twinkle Little Star" in a specific format
# Python exercise: https://www.w3resource.com/python-exercises/python-basic-exercises.php
#
# Write a Python program to print the following string in a specific format (see the output).
# Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are"
# Output :
#
# Twinkle, twinkle, little star,
# How I wonder what you are!
# Up above the world so high,
# Like a diamond in the sky.
# Twinkle, twinkle, little star,
# How I wonder what you are
#
poem = (
"Twinkle, twinkle, little star,",
"How I wonder what you are!",
"Up above the world so high,",
"Like a diamond in the sky.",
"Twinkle, twinkle, little star,",
"How I wonder what you are"
)
i = 0
for line in poem:
prefix = ""
tab = "\t"
if i == 1:
prefix = tab
elif i > 1:
prefix = tab * 2
print(prefix + line)
i += 1
if i > 3 : i = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment