无法打印 ASCII 艺术字
Can't print ASCII art
我正在尝试为我的非常简单的游戏打印 ASCII 艺术作品。
当我尝试 运行 程序时,它只是闪烁了 0.01 秒然后消失了。我还尝试为每个新行使用打印语句。
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
如果这很容易解决并且我很愚蠢,我很抱歉。我只是一个初学者。 ;)
这是我的代码(也可用here):
import random
import os
import time
import sys
mageLvl = 1
def exit():
sys.exit()
def refreshScreen():
clear = lambda: os.system('cls')
clear()
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()
def lvl1():
print(turtle1)
def character():
print(" _,._ ")
print(" .||, /_ _\ ")
print(" \.`',/ |'L'| | ")
print(" = ,. = | -,| L ")
print(" / || \ ,-'\"/,'`. ")
print(" || ,' `,,. `. ")
print(" ,|____,' , ,;' \| | ")
print(" (3|\ _/|/' _| | ")
print(" ||/,-'' | >-'' _,\ ")
print(" ||' ==\ ,-' ,' ")
print(" || | V \ ,| ")
print(" || | |` | ")
print(" || | | \ ")
print(" || | \ \ ")
print(" || | | \ ")
print(" || | \_,-' ")
print(" || |___,,--')_\ ")
print(" || |_| ccc/ ")
print(" || ccc/ ")
print(" || ")
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
def turtle():
print(" ___-------___ ")
print(" _-~~ ~~-_ ")
print(" _-~ /~-_ ")
print(" /^\__/^\ /~ \ / \ ")
print(" /| O|| O| / \_______________/ \ ")
print("| |___||__| / / \ \ ")
print("| \ / / \ \ ")
print("| (_______) /______/ \_________ \ ")
print("| / / \ / \ ")
print(" \ \^\ \ / \ / ")
print(" \ || \______________/ _-_ //\__// ")
print(" \ ||------_-~~-_ ------------- \ --/~ ~\ || __/) ")
print(" ~-----||====/~ |==================| |/~~~~~ ")
print(" (_(__/ ./ / \_\ \. ")
print(" (_(___/ \_____)_) ")
def charName():
name = input("Enter your name: ")
print("Hello there", name, "lvl", mageLvl,"young mage!")
time.sleep(2)
lvl1()
def loading1():
for i in range(2):
print("You are a young wizard with a passion towards your fathers craft... You want to become the best and beat everyone! Survive every tournament!")
print("Loading.")
time.sleep(0.7)
print("Loading..")
time.sleep(0.7)
print("Loading...")
refreshScreen()
readyNo = input("Are you ready? (y/n): ")
if(readyNo == "y" or "yes"):
refreshScreen()
charName()
name = "no one"
titleScreen()
根据您的代码 print_ascii_art.py
turtle = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
print(turtle)
打开命令提示符并在感兴趣的文件所在的文件夹中导航。
进入正确的目录后,键入:
python print_ascii_art.py
这应该可以解决您的问题。
注意:如果您愿意 运行 您的脚本只需双击它,您应该在末尾添加行 input()
你的代码。这样 ascii 艺术将被打印出来,程序将在关闭前等待任何键盘输入。
您忘记在函数 titleScreen()
的最后一行缩进对 refreshScreen()
的调用(来自您的代码示例)。它在程序退出前刷新了屏幕,删除了 ASCII 艺术。
这是修正后的函数 titleScreen
:
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()
我正在尝试为我的非常简单的游戏打印 ASCII 艺术作品。
当我尝试 运行 程序时,它只是闪烁了 0.01 秒然后消失了。我还尝试为每个新行使用打印语句。
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
如果这很容易解决并且我很愚蠢,我很抱歉。我只是一个初学者。 ;)
这是我的代码(也可用here):
import random
import os
import time
import sys
mageLvl = 1
def exit():
sys.exit()
def refreshScreen():
clear = lambda: os.system('cls')
clear()
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()
def lvl1():
print(turtle1)
def character():
print(" _,._ ")
print(" .||, /_ _\ ")
print(" \.`',/ |'L'| | ")
print(" = ,. = | -,| L ")
print(" / || \ ,-'\"/,'`. ")
print(" || ,' `,,. `. ")
print(" ,|____,' , ,;' \| | ")
print(" (3|\ _/|/' _| | ")
print(" ||/,-'' | >-'' _,\ ")
print(" ||' ==\ ,-' ,' ")
print(" || | V \ ,| ")
print(" || | |` | ")
print(" || | | \ ")
print(" || | \ \ ")
print(" || | | \ ")
print(" || | \_,-' ")
print(" || |___,,--')_\ ")
print(" || |_| ccc/ ")
print(" || ccc/ ")
print(" || ")
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
def turtle():
print(" ___-------___ ")
print(" _-~~ ~~-_ ")
print(" _-~ /~-_ ")
print(" /^\__/^\ /~ \ / \ ")
print(" /| O|| O| / \_______________/ \ ")
print("| |___||__| / / \ \ ")
print("| \ / / \ \ ")
print("| (_______) /______/ \_________ \ ")
print("| / / \ / \ ")
print(" \ \^\ \ / \ / ")
print(" \ || \______________/ _-_ //\__// ")
print(" \ ||------_-~~-_ ------------- \ --/~ ~\ || __/) ")
print(" ~-----||====/~ |==================| |/~~~~~ ")
print(" (_(__/ ./ / \_\ \. ")
print(" (_(___/ \_____)_) ")
def charName():
name = input("Enter your name: ")
print("Hello there", name, "lvl", mageLvl,"young mage!")
time.sleep(2)
lvl1()
def loading1():
for i in range(2):
print("You are a young wizard with a passion towards your fathers craft... You want to become the best and beat everyone! Survive every tournament!")
print("Loading.")
time.sleep(0.7)
print("Loading..")
time.sleep(0.7)
print("Loading...")
refreshScreen()
readyNo = input("Are you ready? (y/n): ")
if(readyNo == "y" or "yes"):
refreshScreen()
charName()
name = "no one"
titleScreen()
根据您的代码 print_ascii_art.py
turtle = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
print(turtle)
打开命令提示符并在感兴趣的文件所在的文件夹中导航。
进入正确的目录后,键入:
python print_ascii_art.py
这应该可以解决您的问题。
注意:如果您愿意 运行 您的脚本只需双击它,您应该在末尾添加行 input()
你的代码。这样 ascii 艺术将被打印出来,程序将在关闭前等待任何键盘输入。
您忘记在函数 titleScreen()
的最后一行缩进对 refreshScreen()
的调用(来自您的代码示例)。它在程序退出前刷新了屏幕,删除了 ASCII 艺术。
这是修正后的函数 titleScreen
:
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()