Created
December 27, 2023 04:42
-
-
Save thambaru/4d30c4d8a62882a2ca613da6b7495e0f to your computer and use it in GitHub Desktop.
Python program to print "Twinkle Twinkle Little Star" in a specific format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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