I just finished week 6 lecture and I'm doing the practice problems. I'm stuck with FIGlet, I don't understand why I get the timeout error message with check50 :/
from pyfiglet import Figlet
from sys import argv
import sys
import random
figlet = Figlet()
string = input("Input: ")
# the user would like to output text in a random font.
if len(sys.argv) == 1:
figlet.setFont(font=random.choice(font_list))
print(f"Output: {figlet.renderText(string)}")
# the user would like to output text in a specific font
elif len(sys.argv) == 3 and (argv[1] == "-f" or argv[1] == "--font"):
if argv[2] in figlet.getFonts():
figlet.setFont(font=argv[2])
print(f"Output: {figlet.renderText(string)}")
else:
sys.exit("Invalid usage")
# otherwise error
else:
sys.exit("Invalid usage")
the program works as intended when I do the tests.. Can you please help me out? It's only my second attempt at python so if you also have tips on how to make the code better I would appreciate it!
Don't ask for input when the arguments are invalid. Check the arguments first, then ask for input and print the result at the end.
It's timing out because
check50doesn't provide any input when it gives invalid arguments, so the script is waiting forever for that.