|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么呢这个else是有错误的realprofit=int(input('请输入月利润:'))
standardprofit=[0,100000,200000,400000,600000,1000000]
pushmoney=[0.1,0.075,0.05,0.03,0.015,0.01]
sum=0
for i in range(0,6):
if realprofit > standardprofit[i]:
realpushmoney=(realprofit-standardprofit[i])*pushmoney[i]+realpushmoney
sum=100000*0.1+realpushmoney
else:
本帖最后由 hellomyprogram 于 2023-10-4 17:38 编辑
这个 else 既不与 if 相接(中间有一行缩进少了),也不与 for 相连( else 缩进少了),因此报出了 SyntaxError 。
如果你的 else 是跟着 if 的(更应该是这种),就改成这样:
- realprofit = int(input('请输入月利润:'))
- standardprofit = [0, 100000, 200000, 400000, 600000, 1000000]
- pushmoney = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
- sum = 0
- for i in range(0, 6):
- if realprofit > standardprofit:
- realpushmoney += (realprofit - standardprofit) * pushmoney
- sum = 100000 * 0.1 + realpushmoney
- else:
- ...
复制代码
如果你的 else 是跟着 for 的,就这么改:
- realprofit = int(input('请输入月利润:'))
- standardprofit = [0, 100000, 200000, 400000, 600000, 1000000]
- pushmoney = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
- sum = 0
- for i in range(0, 6):
- if realprofit > standardprofit:
- realpushmoney += (realprofit - standardprofit) * pushmoney
- sum = 100000 * 0.1 + realpushmoney
- else:
- ...
复制代码
另外,我认为你可能想把 realpushmoney 算出来之后无论如何都要计算 sum 的值,这种情况下可能需要改成:
- realprofit = int(input('请输入月利润:'))
- standardprofit = [0, 100000, 200000, 400000, 600000, 1000000]
- pushmoney = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
- sum = 0
- for i in range(0, 6):
- if realprofit > standardprofit:
- realpushmoney += (realprofit - standardprofit) * pushmoney
- sum = 100000 * 0.1 + realpushmoney
- if realprofit <= standardprofit:
- ...
复制代码
我假设你在这段代码之前初始化了 realpushmoney (你有可能忘记了初始化),并在 else 后面还写了更多内容。
|
|