Python编译时提示错误 IndentationError: unexpected indent

问题描述:

我是昨天才开始学的Python,今天尝试练习下写了个小Demo,运行的时候报错了,提示第二行有个错误IndentationError: unexpected indent。
a=int(input('请输入a值:'))
    print('您输入的a=',a)
b=int(input('请输入b值:'))
    print('您输入的b=',b)
print('a+b=',a+b);

分析: indentation是缩进的意思。unexpected indent 就是说第二行这里存在一个“意外的”缩进。也就是说,这里的问题就是指“print”是一个意外的缩进。可以看到第二行是缩进了一个字符位。查了下百度,看了下别人说好像取消缩进顶格写,就可以了。

a=int(input('请输入a值:'))
print('您输入的a=',a)
b=int(input('请输入b值:'))
print('您输入的b=',b)
print('a+b=',a+b);

结论: 在python中,每一句代码都应该顶格写。

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
IndentationError: unexpected indentPython中的一个常见错误,意味着代码中存在意外的缩进。 在Python中,缩进是非常重要的,它用于表示代码块的开始和结束。正确的缩进方式是使用4个空格或者一个制表符来缩进代码。当代码中出现意外的缩进,即缩进不一致或者有多余的缩进,就会引发IndentationError: unexpected indent错误。 解决这个错误的方法很简单,只需要检查代码的缩进是否正确即可。请确保所有代码行都顶格写,即没有多余的缩进或者缩进不一致的情况。同,也要注意避免在代码块中使用不同数量的空格或制表符进行缩进。 在你提供的例子中,错误是因为在第19行的print('a')语句存在一个意外的缩进。你可以将这行代码顶格写,即取消缩进,就可以解决这个错误。 总结起来,解决IndentationError: unexpected indent错误的方法是检查代码的缩进是否正确,并确保所有代码行都顶格写。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python编译提示错误IndentationError: unexpected indent](https://blog.csdn.net/LittleGiantWang/article/details/120648794)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [python出现"IndentationError: unexpected indent"错误解决办法](https://download.csdn.net/download/weixin_38571759/12872139)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值