我做错了什么?|Python代码未运行

2024-03-29 08:07:00 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么python代码似乎不想运行,我在空闲状态下尝试了所有操作,它说“RESTART”,然后是文件名,在PyCharm上说“processfinished with exit code 0”,所以我不知道我做错了什么。你知道吗

我还想补充一点,如果我错过了一些愚蠢的东西,我很抱歉不久前我刚刚开始Python,这是我想要做的一个开始项目。你知道吗

我们将不胜感激。你知道吗

import time
import os

def main_interface():
    print("Welcome to The Adventures!")
    print('''/nNew Game/nOptions/nExit''')
    loading_choose = input()
    loading_choose = loading_choose.lower()

    if loading_choose == 'New Game':
        new_game()

    elif loading_choose == 'Options':
        options()


def options():
    print("Welcome To Options")
    time.sleep(1)
    print("\nGraphics\nAudio\nExit")
    options = input()
    options.lower()

    if options == 'Graphics':
        graphic_interface()

    elif options == 'Audio':
        audio_interface()

    elif options == 'Exit':
        main_interface()

def graphic_interface():
    print("What Graphics Would You Like?")
    print("\nLow\nMedium\nHigh")
    graphics = input()
    graphics = graphics.lower()

    if graphics == 'Low':
        print("Graphics Set To Low")
        options()

    elif graphics == 'Medium':
        print("Graphics Set To Medium")
        time.sleep(1)
        options()

    elif graphics == 'High':
        print("Graphics Set To High")
        time.sleep(1)
        options()

def audio_interface():
    print("What Do You Want Your Volume To Be?")
    print("0-100")
    volume = input()

    if volume <100:
        print("Volume Greater Then 100")
        time.sleep(1)
        print("Try Again!")
        audio_interface()
    else:
        print("Volume Set To"+volume)
        options()

Tags: toinputiftimedefsleepinterfaceoptions
2条回答

IDLE/Pycharm没有做任何事情的原因是因为代码没有做任何事情。我的意思是没有函数被你的程序调用-它只是一堆函数。你知道吗

要解决这个问题,只需在程序中调用一个函数(在函数外编写)。你知道吗

这是一个简单的错误,但是考虑到您已经开始使用python,这是完全可以理解的。你知道吗


但是,我也看到没有定义new_game()函数,您可以在main_interface()函数中调用它。另外,在audio_interface()函数中,input()函数返回的是str而不是int,因此您需要将结果转换为int,如下所示:

volume = int(input())

学习愉快!你知道吗

添加

main_interface()

运行函数主界面的脚本结尾。你知道吗

删除行loading_choose = loading_choose.lower() 因为它将输入文本转换为小写,并且不支持任何选项。你知道吗

相关问题 更多 >