在这个 python 程序中,我在哪里得到了想要的结果?
where i am wrong to get desire result in this python program?
这个程序是为了我自己的练习目的。该程序必须计算两个列表(每个列表 5 个数字)的百分比并进行比较。数字将由用户输入。
def percentage(mark):
percentage = (((sum(mark))/500)*100)
return percentage
mark1=[]
for j in range (1,6):
a=int(input(f'Enter mark{j}: '))
mark1.append(a)
percentage1=percentage(mark1)
mark2=[]
for i in range(1,6):
b=int(input(f'enter mark{i}: '))
mark2.append(a)
percentage2=percentage(mark2)
print(f'percentage of boy 1 is {percentage1} and boy 2 is {percentage2}')
if percentage1 > percentage2:
print('Boy 1 is topper')
else:
print ('boy 2 is topper')
您应该将第二个输入附加到第二个标记,而不是第一个输入。
def percentage(mark):
percentage = (((sum(mark))/500)*100)
return percentage
mark1=[]
for j in range (1,6):
a=int(input(f'Enter mark{j}: '))
mark1.append(a)
percentage1=percentage(mark1)
mark2=[]
for i in range(1,6):
b=int(input(f'enter mark{i}: '))
mark2.append(b) # <--- append b, not a !!
percentage2=percentage(mark2)
print(f'percentage of boy 1 is {percentage1} and boy 2 is {percentage2}')
if percentage1 > percentage2:
print('Boy 1 is topper')
else:
print ('boy 2 is topper')
这个程序是为了我自己的练习目的。该程序必须计算两个列表(每个列表 5 个数字)的百分比并进行比较。数字将由用户输入。
def percentage(mark):
percentage = (((sum(mark))/500)*100)
return percentage
mark1=[]
for j in range (1,6):
a=int(input(f'Enter mark{j}: '))
mark1.append(a)
percentage1=percentage(mark1)
mark2=[]
for i in range(1,6):
b=int(input(f'enter mark{i}: '))
mark2.append(a)
percentage2=percentage(mark2)
print(f'percentage of boy 1 is {percentage1} and boy 2 is {percentage2}')
if percentage1 > percentage2:
print('Boy 1 is topper')
else:
print ('boy 2 is topper')
您应该将第二个输入附加到第二个标记,而不是第一个输入。
def percentage(mark):
percentage = (((sum(mark))/500)*100)
return percentage
mark1=[]
for j in range (1,6):
a=int(input(f'Enter mark{j}: '))
mark1.append(a)
percentage1=percentage(mark1)
mark2=[]
for i in range(1,6):
b=int(input(f'enter mark{i}: '))
mark2.append(b) # <--- append b, not a !!
percentage2=percentage(mark2)
print(f'percentage of boy 1 is {percentage1} and boy 2 is {percentage2}')
if percentage1 > percentage2:
print('Boy 1 is topper')
else:
print ('boy 2 is topper')