大佬们帮我看一下这个python程序怎么修改,
i=int(raw_input('净利润:'))arr=[1000000,6000000,4000000,2000000,1000000,0]rat=[0.01,0.01...
i = int(raw_input('净利润:'))
arr = [1000000,6000000,4000000,2000000,1000000,0]
rat = [0.01,0.015,0.03,0.05,0.075,0.1]
r = 0
for idx in range(0,6):
if i>arr[idx]:
r+=(i-arr[idx])*rat[idx]
print (i-arr[idx])*rat[idx]
i=arr[idx]
print(r)
下面是错误报告:
Traceback (most recent call last):
File "E:/Python程序代码/经典100实例/第二例.py", line 1, in <module>
i = int(raw_input('净利润:'))
NameError: name 'raw_input' is not defined 展开
arr = [1000000,6000000,4000000,2000000,1000000,0]
rat = [0.01,0.015,0.03,0.05,0.075,0.1]
r = 0
for idx in range(0,6):
if i>arr[idx]:
r+=(i-arr[idx])*rat[idx]
print (i-arr[idx])*rat[idx]
i=arr[idx]
print(r)
下面是错误报告:
Traceback (most recent call last):
File "E:/Python程序代码/经典100实例/第二例.py", line 1, in <module>
i = int(raw_input('净利润:'))
NameError: name 'raw_input' is not defined 展开
2个回答
展开全部
## 语法错误改正 如下:
n=int(input("输入一个整数:"))
a1=0
a2=1
if n%2==0:
for i in range(n):
a1=a1+1
for i in range(n//液键液2-1):
a2=a2+2
else:
for i in range(n):
a1=a2+1
for i in range(n//2):
a1=a2+2
print("从1到N相加的结果和从1到N奇亮胡数相加的结果分别是%d和%d"%(a1,a2))
其实应该如此吧:
n=int(input("输入一个整数:"))
a1=0
a2=0
for i in range(n+1):
a1=a1+i
for i in range(1,n+1,2):
a2=a2+i
print("从1到N相加的结果和闹物从1到N奇数相加的结果分别是%d和%d"%(a1,a2))
n=int(input("输入一个整数:"))
a1=0
a2=1
if n%2==0:
for i in range(n):
a1=a1+1
for i in range(n//液键液2-1):
a2=a2+2
else:
for i in range(n):
a1=a2+1
for i in range(n//2):
a1=a2+2
print("从1到N相加的结果和从1到N奇亮胡数相加的结果分别是%d和%d"%(a1,a2))
其实应该如此吧:
n=int(input("输入一个整数:"))
a1=0
a2=0
for i in range(n+1):
a1=a1+i
for i in range(1,n+1,2):
a2=a2+i
print("从1到N相加的结果和闹物从1到N奇数相加的结果分别是%d和%d"%(a1,a2))
追问
你这是从哪里复制的代码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询