Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtashzol
1,354 PointsI created two functions, each of them animating a group of strings of text. They won't run when functions are called.
I hope my question is relevant here, although it is not directly derived from a particular Treehouse exercise, but it's a side-project or experiment of mine, let's say, as a part of learning process. So, I created a little program that should animate a couple of blocks of ASCII characters, taking advantage of termcolor for representing colours in text. I am using the terminal on my Arch Linux box to run it. Each animation per se, when run in a separate program, runs perfectly, as I intended to, but when I try to put them all in one program, and present a choice which would allow to load either of these, based on user input, nothing happens, nothing is printed on the screen, no errors neither. I can'get it right. I tried a dozen of possible combinations of using if and else, then if and elif, using if and elif and else, using procedure instead of defining the functions and calling them, but nothing seems to work. Does anyone have any idea what I am doing wrong here? Thanks!
from termcolor import colored
import os
import time
def animate_Beastie():
distanceFromTop = 20
while True:
print("\n" * distanceFromTop)
print(colored(" , ,", "red"))
print(colored(" /( )`", "red"))
print(colored(" \ \___ / |", "red"))
print(colored(" /- _ `-/ '", "red"))
print(colored(" (/\/ \ \ /\\", "red"))
print(colored(" / / | ` \\", "red"))
print(colored(" O O", "green"), colored(" ) / |", "red"))
print(colored(" `-^--'`< '", "red"))
print(colored(" (_.) _ ) /", "red"))
print(colored(" `.___/` /", "red"))
print(colored(" `-----' /", "red"))
print(colored(" <----.", "yellow"), colored(" __ / __ \\", "red"))
print(colored(" <----|====O)))==) \) /====", "yellow"))
print(colored(" <----'", "yellow"), colored(" `--' `.__,' \\", "red"))
print(colored(" | |", "red"))
print(colored(" \ /", "red"))
print(colored(" ______", "blue"), colored(" (_ / \______", "red"))
print(colored(" ,' ,-----' |", "blue"), colored(" \\", "red"))
print(colored(" `--{__________)", "blue"), colored(" \/", "red"))
print(colored(" tlil", "green"), colored("=]", "red"), colored("beastie", "green"))
time.sleep(0.20)
os.system('clear')
distanceFromTop -= 1
if distanceFromTop < 0:
distanceFromTop = 20
def animate_Invader():
distanceFromTop = 0
distanceFromLeftSide = 0
step = 1
while True:
print("\n" * distanceFromTop)
print((" " * distanceFromLeftSide) + " (-.)")
print((" " * distanceFromLeftSide) + " cc )")
print((" " * distanceFromLeftSide) + " 3-n-(")
print((" " * distanceFromLeftSide) + " _(|/`->)")
distanceFromLeftSide +=step
if distanceFromLeftSide>20 or distanceFromLeftSide<=0:
step = -step
distanceFromTop += 2
if distanceFromTop >20:
distanceFromTop = 0
distanceFromLeftSide = 0
step = 1
time.sleep(0.05)
os.system('clear')
choice = input("Enter (A) for Beastie or (B) for Invader: ")
if choice.lower == "a":
animate_Beastie()
elif choice.lower == "b":
animate_Invader()
2 Answers
KRIS NIKOLAISEN
54,967 Pointslower should be followed by parentheses
if choice.lower() == "a":
animate_Beastie()
elif choice.lower() == "b":
animate_Invader()
tashzol
1,354 PointsThanks, it worked! :-)