简体   繁体   English

我的代码不起作用,我该如何解决?

[英]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.

相关问题 我已经在 pyCharm 上测试了我的代码并且它可以工作,但是在 Leetcode 上它给了我一个 KeyError 并且不起作用。 我如何解决它? - I have tested my code on pyCharm and it works, but on Leetcode it gives me a KeyError and doesn't work. How do I fix it? 为什么我的 python pandas Z6A8064B5DF4794555500553C47C55057DZ 条带方法不适用于尾随空格? 我该如何解决? - why doesn't my python pandas dataframe strip method work for trailing whitespace? and how do I fix it? 如何在 Python 中使用嵌套列表遍历列表/为什么我的代码不起作用? - How do I iterate through lists with nested lists in Python / why doesn't my code work? 如何在代码中修复语法,以使单选按钮可与字典配合使用? - How do I fix the syntax in my code to make my radio buttons work with my dictionary? tkinter:如何修复窗口,以便在调整内容大小时不调整窗口大小? - tkinter: How do I fix my window so that the window doesn't resize when my content resizes? 如何从代码中的 bs4 标签元素中提取文本? 使用内容 function 不起作用 - How do I extract text from bs4 tag elements in my code? Using contents function doesn't work 当安装程序不起作用时,如何正确卸载/修复 python 3.8.5? - How do I properly uninstall/fix python 3.8.5 when the installer doesn't work? 使用控件时,我的游戏将无法正常工作,该如何解决? - My game won't work when I use the controls, how do I fix it? 如何修复我的子弹代码,以便当我从不同方向射出第二颗子弹时,这不会改变第一颗子弹的方向? - How do I fix my bullet code so that when I shoot a second bullet from different direction, that doesn't change the first bullet's directions? 我的代码不允许一个字符出现 2 次(如何修复) - My code doesn't allow 2 times a character (how to fix)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM