aliciacgu
aliciacgu

Reputation: 23

unwanted print repetition

I'm doing a simple function to print a color with an input that gives me the first letter of the word but I don't know why it prints it a lot of times.

color_letter=input("Please write the first letter of your favorite color: ")

def rainbow_color(color_letter):

    if color_letter.lower()=="r":
        print("Red!")
    elif color_letter.lower()=="o":
         print("That's orange!")
    elif color_letter.lower()=="y":
        print("That most be yellow")
    elif color_letter.lower()=="g":
        print("Green!")
    elif color_letter.lower()=="b":
        print("is it blue?")
    elif color_letter.lower()=="i":
        print("why would you choose indigo wirdo")
    elif color_letter.lower()=="v":
        print("Aww violet")
    else:
        print("wtf are you talking about")

    return  rainbow_color(color_letter)



print(rainbow_color(color_letter))

This is what I get (But way too more)

Please write the first letter of your favorite color: r

Red!

Red!

Red!

Red!

Upvotes: 0

Views: 38

Answers (1)

KuboMD
KuboMD

Reputation: 684

Replace your "prints" with returns. Your original return statement is calling your function again, which is printing the color when it should be returning it.

if color_letter.lower()=="r":
    return "Red!"

Upvotes: 1

Related Questions