[英]My Code just doesn't work, how do I fix it?
Basicly I just made a Calculator Code (it should probably work) but is just shows the Ascii Art CALC but doesn't actually run the Calculator Code, no error or anything, just doesn't run a Part of Code for some Reason.基本上我只是做了一个计算器代码(它应该可以工作),但只是显示了 Ascii Art CALC ,但实际上并没有运行计算器代码,没有错误或任何东西,只是由于某种原因没有运行代码的一部分。 -_- (The Ascii Art in the Code may look messy but actually its ok in the cmd) -_- (代码中的 Ascii 艺术可能看起来很乱,但实际上在 cmd 中没问题)
import time
from colorama import init, Fore
init()
print(Fore.CYAN)
print(" _______ ____ ___ _______")
print(" / | / \\ | | / |")
print("| ____/ / /\\ \\ | | | ____/")
print("| | | / \\ | | | | |")
print("| | | ¯¯¯¯ | | | | |")
print("| | | __ | | | | |")
print("| ¯¯¯¯\\ | | | | | ¯¯¯¯¯¯\\ | ¯¯¯¯\\")
print(" \\ | | | | | | | \\ | U L A T O R //made by dot.")
print(" ¯¯¯¯¯¯¯ ¯¯ ¯¯ ¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯")
print(Fore.WHITE)
def start():
func = input("\n+ - * / : ")
p = input("Math Problem: ")
pl_ps = p.split(" + ")
mi_ps = p.split(" - ")
mu_ps = p.split(" * ")
di_ps = p.split(" / ")
if func == "+":
one = int(pl_ps[0])
two = int(pl_ps[1])
answer = one + two
print(answer)
elif func == "-":
one = int(mi_ps[0])
two = int(mi_ps[1])
answer = one - two
print(answer)
elif func == "\*":
one = int(mu_ps[0])
two = int(mu_ps[1])
answer = one * two
print(answer)
else:
if func == "/":
one = int(di_ps[0])
two = int(di_ps[1])
answer = one / two
print(answer)
else:
print("The option " + '"'+func+'"' + " does not exist.")
def e():
exit = input("Restart(r),Exit(e): ")
if exit == "r":
start()
else:
if exit == "e":
print("Closing Programm...")
time.sleep(1)
else:
print("The option " + '"'+exit+'"' + " does not exist.")
time.sleep(1)
e()
You never call your functions.你永远不会调用你的函数。 They don't automatically run if they don't get called.如果没有被调用,它们不会自动运行。 So you can call it like yourfuncname()
.所以你可以把它yourfuncname()
。
import time
from colorama import init, Fore
init()
print(Fore.CYAN)
print(" _______ ____ ___ _______")
print(" / | / \\ | | / |")
print("| ____/ / /\\ \\ | | | ____/")
print("| | | / \\ | | | | |")
print("| | | ¯¯¯¯ | | | | |")
print("| | | __ | | | | |")
print("| ¯¯¯¯\\ | | | | | ¯¯¯¯¯¯\\ | ¯¯¯¯\\")
print(" \\ | | | | | | | \\ | U L A T O R //made by dot.")
print(" ¯¯¯¯¯¯¯ ¯¯ ¯¯ ¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯")
print(Fore.WHITE)
def start():
func = input("\n+ - * / : ")
p = input("Math Problem: ")
pl_ps = p.split(" + ")
mi_ps = p.split(" - ")
mu_ps = p.split(" * ")
di_ps = p.split(" / ")
if func == "+":
one = int(pl_ps[0])
two = int(pl_ps[1])
answer = one + two
print(answer)
elif func == "-":
one = int(mi_ps[0])
two = int(mi_ps[1])
answer = one - two
print(answer)
elif func == "\*":
one = int(mu_ps[0])
two = int(mu_ps[1])
answer = one * two
print(answer)
else:
if func == "/":
one = int(di_ps[0])
two = int(di_ps[1])
answer = one / two
print(answer)
else:
print("The option " + '"'+func+'"' + " does not exist.")
def e():
exit = input("Restart(r),Exit(e): ")
if exit == "r":
start()
else:
if exit == "e":
print("Closing Programm...")
time.sleep(1)
else:
print("The option " + '"'+exit+'"' + " does not exist.")
time.sleep(1)
e()
if __name__ == "__main__":
start()
e()
how are you running your script?你是如何运行你的脚本的? Is it being called by another script or are you running this script directly?它是被另一个脚本调用还是直接运行这个脚本? If the latter, you never called start()
如果是后者,你永远不会调用start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.