如何使用缩进修复Python上的语法错误? [英] How Do I Fix My Syntax Error On Python With Indentation?

查看:267
本文介绍了如何使用缩进修复Python上的语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  while  True:
try
choice =( yes
choice1 =( no
user5 = input( < span class =code-string>你的手机工作)
除了ValueError:
print( 抱歉,我不明白。
继续
if user5 == choice:
print( that that great
elif user5 == choice1:
print( 你可以联系卖家
user_response = input( 现在修复了吗?
继续
其他
print( 回答是或否
break ;
if user_response == choice:
print( 那太好了
sys.exit( 0
elif user_response == choice1:
print( 你可以尝试这个..
else
print( 回答是或否



它一直在说语法错误,但我不确定,我该如何解决它

解决方案

  while   True 
尝试
choice =( yes
choice1 =( no
user5 = inp ut( 是您的手机正常工作
ValueError:
print 抱歉,我不明白。
继续
if user5 == choice:
print 多数
elif user5 == choice1:
print 您可以联系卖家
user_response =输入( 现在是否修复?
继续
其他
print 回答是或否
break ;
if user_response == choice:
print 那太好了
sys.exit( 0
elif user_response == choice1:
print 你可以尝试这个..
else
print 回复是或者没有



缩进很容易修复。现在你只需要美化你的输出并修复逻辑。


我遇到了一些问题:



  • try:语句之后的代码没有缩进。
  • 之前没有空格,除了
  • 由于缺少缩进,我无法看到if语句是否属于while循环,但如果是,则缩进它们。
  • 我很确保 break 语句是else子句的一部分,所以缩进它。


了解更多关于Python缩进: 2。词法分析 - Python 3.5.1文档 [ ^ ]

while True:
    try:
choice=("yes")
choice1=("no")
user5=input("is your phone working")
except ValueError:
        print("Sorry, I didn't understand that.")
        continue
if user5==choice:
    print("thats great")
elif user5==choice1:
    print("you could contact seller")
    user_response=input("is it now fix?")
   continue
else:
    print("reply with yes or no")
break;
if user_response==choice:
    print("thats great")
    sys.exit(0)
elif user_response==choice1:
    print("you can try this..")
else:
    print("reply with yes or no")


its keeps on saying syntax error, but i'm not sure, how i am to fix it

解决方案

while True:
    try:
        choice=("yes")
        choice1=("no")
        user5=input("is your phone working")
    except ValueError:
        print("Sorry, I didn't understand that.")
        continue
    if user5==choice:
        print("thats great")
    elif user5==choice1:
        print("you could contact seller")
        user_response=input("is it now fix?")
        continue
    else:
        print("reply with yes or no")
        break;
    if user_response==choice:
        print("thats great")
        sys.exit(0)
    elif user_response==choice1:
        print("you can try this..")
    else:
        print("reply with yes or no")


Indentation is fairly easy to fix. Now you just need to prettify your outputs and fix the logic.


I'm seeing a few problems:

  • The code after the try: statement isn't indented.
  • There are no spaces before except.
  • Because of the missing indentation I cannot see whether the if statements belong to the while loop, but if they do, indent them.
  • I'm quite sure that the break statement is a part of the else clause, so indent it.

Read more about the Python indentation here: 2. Lexical analysis — Python 3.5.1 documentation[^]


这篇关于如何使用缩进修复Python上的语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆