You need to enable JavaScript to run this app. Python3.5.9 IDLE开发缩进报错求解及缩进辅助线设置咨询
优惠活动
大模型
产品
解决方案
定价
更多

Python3.5.9 IDLE开发缩进报错求解及缩进辅助线设置咨询

问题修复方案

一、代码缩进及逻辑错误修正

你代码里的问题主要集中在缩进层级错误、冗余重复代码、低级拼写错误三类,修复时也对重复的条件判断做了合并简化,更易读:

修复后完整代码:

import time
import sys

def play_game_yn (): # 询问是否要玩游戏
    time.sleep(1.5)
    play_game=input('Do you want to play a game? (y/n)')

    if play_game=='Y' or play_game=='y':
        play_yes()
    elif play_game=='N' or play_game=='n':
        play_game_sure=input("Are you sure you don't want to play? (y/n)") # 确认是否真的不玩
        if play_game_sure=='Y' or play_game_sure=='y':
            play_no()
        elif play_game_sure=='N' or play_game_sure=='n':
            play_yes()
        else:
            print("Please enter 'y'or'n'") 
            time.sleep(2)
            play_game_yn()
    else:
        print("Please enter 'y'or'n'") 
        time.sleep(2)
        play_game_yn()


def play_yes(): # 选择要玩的逻辑
    print("Woohoo,")
    time.sleep(0.5)
    game=input("What game do you want to play?") # 询问想玩什么游戏
    print("Uhmm...")
    time.sleep(2)
    print("Let me think...")
    time.sleep(1)
    print("Nope, doesn't ring any bells")
    time.sleep(0.75)
    print("Sorry,", name + ", I have no clue how to play", game + "")
    time.sleep(5)
    sys.exit()

def play_no (): # 选择不玩的逻辑
    print('Awwh, it was fun while it lasted')
    time.sleep(1)
    print('See ya around,',name + '')
    time.sleep(2)
    sys.exit()

name=input("Hey there, I'm SIRB, Super Intelligent Robot Boy, what's your name?") # 自我介绍并询问姓名

if name=='harry' or name=='Harry':
    print("hey, that's the same name as the person who made me :)")
    time.sleep(2)
    print('Hello, ' + name + ', it is nice to meet you')
    play_game_yn()
else:
    print('Hello, ' + name + ', that is a nice name, nice to meet you')
    play_game_yn()

二、IDLE开启制表位垂直辅助线方法

操作步骤:

  • 打开IDLE编辑器,点击顶部菜单栏的Options(选项)
  • 选择Configure IDLE(配置IDLE)
  • 在弹出的设置窗口中切换到General(常规)标签页
  • 找到Show indentation guides(显示缩进参考线)选项,勾选前面的复选框
  • 点击Apply(应用)再点Ok(确定)即可生效,编辑界面会显示对应垂直参考线

内容的提问来源于stack exchange,提问作者SharkFinGuy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.17 13:24:03