-1

I'm currently trying to make something for somebody, I'm a beginner to Python (and programming in general, besides a bit of experience in bash scripting, so go easy on me) I am having an issue where in my loop the output appears stretched and I don't know why, need some help with this (all names/personal stuff replaced with _)

#!/usr/bin/python3

# To _ :)
import sys
import os
import codecs
import colorama
import time

colorama.init()

# No idea why this comes out correct...

row_1 = "                      ❤️           ❤"
row_2 = "                    ❤️ ️❤️       ❤️  ❤"
row_3 = "                  ❤️      ❤️   ❤️      ❤"
row_4 = "                ❤️        ️❤️ ❤️          ❤"
row_5 = "              ❤️️           ️    ️          ❤"
row_6 = "                ❤️       For _____        ❤️"
row_7 = "                  ❤️     From ____      ❤"
row_8 = "                    ❤️                ❤"
row_9 = "                      ❤️            ❤"
row_10 = "                        ❤️        ❤"
row_11 = "                          ❤️    ❤"
row_12 = "                           ️ ❤️"
heart_list = [ row_1, row_2, row_3, row_4, row_5, row_6, row_7, row_8, row_9, row_10, row_11, row_12 ]

for weird in heart_list:
    print(colorama.Fore.RED + weird)
msg = """

    _________________________

"""
print(colorama.Style.RESET_ALL)
print("Type the number beside the thing you want to do, then press enter.")
Start_Menu = "1. My message \n" \
             "2. Heart (color) \n" \
             "3. Heart \n" \
             "4. Exit \n"
while True:
    print(Start_Menu)
    selection = input()

    if selection == "1":
        print(colorama.Fore.MAGENTA + msg)
        print(colorama.Style.RESET_ALL)

    if selection == "2":
        print("Not done yet")
        break
    if selection == "3":
        for whatever in heart_list:
            print(colorama.Fore.RED + whatever)
        print(colorama.Style.RESET_ALL)
    if selection == "4":
        print("___")
        exit()

# Time for the colorful heart
os.system("clear")
while True:
    time.sleep(1)
    red = False
    green = False
    yellow = False
    blue = False
    magenta = False
    cyan = False
    color_list = [ red, green, yellow, blue, magenta, cyan ]
    count = 0
    for current in heart_list:
        count += 1
    for current_2 in color_list:
        if all(color_list)  == True: # If everything in list is true...
            red = False
            green = False
            yellow = False
            blue = False
            magenta = False
            cyan = False
        if red == False: # False = not yet present
            print(colorama.Fore.RED)
            red = True
            break
        if green == False:
            print(colorama.Fore.GREEN)
            green = True
            break
        if yellow == False:
            print(colorama.Fore.YELLOW)
            yellow = True
            break
        if blue == False:
            print(colorama.Fore.BLUE)
            blue = True
            break
        if magenta == False:
            print(colorama.Fore.MAGENTA)
            magenta = True
            break
        if cyan == False:
            print(colorama.Fore.CYAN)
            cyan = True
    print(current)
    print(colorama.Style.RESET_ALL)
    if count == 12:
        os.system("clear")

https://pypi.org/project/colorama/ (colorama, a library I'm using)

Here is what the output looks like when in the bottom loop:

https://pastebin.com/ (also, in my terminal it stops using any color once it gets to the "From _" line, if you could tell me why thats happening too that would be great)

For reference this is what it looks like when printed in the for loop near the top:

https://pastebin.com/aQwGnhZ8 (everything appears to be straight when outputted to my terminal, if anybody could explain this as well that would also be great, but as you can see it's not stretched)

I'm trying to make a heart that changes colors (like, if line 1 was blue, line 2 was red, and line 3 was green. The next loop it would be line 1 green, line 2 blue, line 3 red, etc).

Thanks in advance

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Sol33t303
  • 105
  • 1
  • 7

1 Answers1

0

This is because print adds a newline character (like hitting the enter key) after its output. When you print out the colour for a line, it is printing a newline character, which means you have an extra newline between rows.

You need to use the end keyword argument to suppress the newline character.

print(colorama.Fore.MAGENTA, end="")

How can I suppress the newline after a print statement?

Theo Emms
  • 293
  • 1
  • 7
  • Thanks for the help, I knew that print automatically prints a new line, but didn't think that was the cause of the issue. – Sol33t303 Nov 08 '18 at 13:01