-2

Hello I'm trying to make a python script to loop text and toggle through it. I'm able to get python to toggle through the text once but what I cant get it to do is to keep toggling through the text. After it toggles through the text once I get a message that says

Traceback (most recent call last): File "test.py", line 24, in hello() File "test.py", line 22, in hello hello() TypeError: 'str' object is not callable

import time, sys, os 
from colorama import init
from termcolor import colored

def hello():
    os.system('cls')
    init()

    hello = '''Hello!'''

    print(colored(hello,'green',))
    time.sleep(1)
    os.system('cls')

    print(colored(hello,'blue',))
    time.sleep(1)
    os.system('cls')

    print(colored(hello,'yellow',))
    time.sleep(1)
    os.system('cls')
    hello()

hello()
Jake
  • 37
  • 1
  • 8

3 Answers3

0

You're overwriting the hello function with a string also called hello in the hello function. You could try to rename your hello string to greeting and using that instead.

Joost
  • 3,609
  • 2
  • 12
  • 29
0

You are using the name hello for two different purposes, and they are conflicting.

You use it both for the function name and for a variable in the function. Change the name of one of them everywhere it is used and try again.

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
0

you have both a variable and a function called hello so in the scope of the function hello is being overwritten. This can be fixed easily by renaming your string:

import time, sys, os
from colorama import init
from termcolor import colored

def hello():
    os.system('cls')
    init()

    greeting = '''Hello!'''

    print(colored(greeting,'green',))
    time.sleep(1)
    os.system('cls')

    print(colored(greeting,'blue',))
    time.sleep(1)
    os.system('cls')

    print(colored(greeting,'yellow',))
    time.sleep(1)
    os.system('cls')
    hello()

hello()
ktzr
  • 1,625
  • 1
  • 11
  • 25