import pyfiglet
from termcolor import colored
total_colors = ["red", "green", "yellow", "blue", "magenta", "cyan", "white"]
msg = input("What would you like to print? ")
col = input("what color?")
if col not in total_colors:
col = "green"
ascii_art = pyfiglet.figlet_format(msg)
colored_ascii = colored(ascii_art, color=col)
print(colored_ascii)
ImportError:无法从“ pyfiglet”导入名称“ figlet_format”
答案 0 :(得分:1)
我在程序中看到一些问题。
1。安装pyfiglet模块
pip install pyfiglet
2。msg = input("What would you like to print? ")
无需输入此行,因为下一行接受输入,并且程序的逻辑基于下一个输入
3。ascii_art = pyfiglet.figlet_format(msg) colored_ascii = colored(ascii_art, color=col) print(colored_ascii)
上面的行应该是
ascii_art = pyfiglet.figlet_format(col) colored_ascii = colored(ascii_art, color=col) print(colored_ascii)
我安装了pyfiglet模块并实现了修改后的程序
import pyfiglet
from termcolor import colored
total_colors = ["red", "green", "yellow", "blue", "magenta", "cyan", "white"]
msg = print("What would you like to print? ")
col = input("what color?")
if col not in total_colors: col = "green"
ascii_art = pyfiglet.figlet_format(col)
colored_ascii = colored(ascii_art, color=col)
print(colored_ascii)
输出:
What would you like to print?
what color?blue
[34m _ _
| |__ | |_ _ ___
| '_ \| | | | |/ _ \
| |_) | | |_| | __/
|_.__/|_|\__,_|\___|
[0m
答案 1 :(得分:0)
我知道这听起来很明显,但是请确保在您的计算机上安装了lib。如果是这样,请确保将lib安装在与Python安装位置相同的位置。