数组的百分比

时间:2014-09-11 06:04:44

标签: python

嗨,我这个python程序遇到了麻烦。它一直说百分比是=到0.0

players_goals = ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]
players_fouls = ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]

players_goals[0] = int(input("type in number of goals for player 1 then press enter "))
players_goals[1] = int(input("type in number of goals for player 2 then press enter "))
players_goals[2] = int(input("type in number of goals for player 3 then press enter "))
players_goals[3] = int(input("type in number of goals for player 4 then press enter "))
players_goals[4] = int(input("type in number of goals for player 5 then press enter "))
players_goals[5] = int(input("type in number of goals for player 6 then press enter "))
players_goals[6] = int(input("type in number of goals for player 7 then press enter "))
players_goals[7] = int(input("type in number of goals for player 8 then press enter "))
players_goals[8] = int(input("type in number of goals for player 9 then press enter "))
players_goals[9] = int(input("type in number of goals for player 10 then press enter "))
players_goals[10] = int(input("type in number of goals for player 11 then press enter "))

players_fouls[0] = int(input("Now type in number of fouls for player 1 then press enter "))
players_fouls[1] = int(input("type in number of fouls for player 2 then press enter "))
players_fouls[2] = int(input("type in number of fouls for player 3 then press enter "))
players_fouls[3] = int(input("type in number of fouls for player 4 then press enter "))
players_fouls[4] = int(input("type in number of fouls for player 5 then press enter "))
players_fouls[5] = int(input("type in number of fouls for player 6 then press enter "))
players_fouls[6] = int(input("type in number of fouls for player 7 then press enter "))
players_fouls[7] = int(input("type in number of fouls for player 8 then press enter "))
players_fouls[8] = int(input("type in number of fouls for player 9 then press enter "))
players_fouls[9] = int(input("type in number of fouls for player 10 then press enter "))
players_fouls[10] = int(input("type in number of fouls for player 11 then press enter "))

print""                       
print"the total number of goals is ", players_goals[0] + players_goals[1] + players_goals[2] + players_goals[3] + players_goals[4] + players_goals[5] + players_goals[6] + players_goals[7] + players_goals[8] + players_goals[9] + players_goals[10]
print"the total number of fouls is ", players_fouls[0] + players_fouls[1] + players_fouls[2] + players_fouls[3] + players_fouls[4] + players_fouls[5] + players_fouls[6] + players_fouls[7] + players_fouls[8] + players_fouls[9] + players_fouls[10]

print"player 1's goal percentage is ", (players_goals[0] / (players_fouls[0] + players_goals[0])) * 100.0

我的问题在最后一行。无论我放入什么,总是= 0

感谢您的帮助 附:我正在使用python 3.4.1

1 个答案:

答案 0 :(得分:-1)

如果输入正整数,则player_goals [0]< =(players_fouls [0] + players_goals [0]。 所以players_goals [0] /(players_fouls [0] + players_goals [0] = 0,就像python中的2 /(1 + 2)= 0。 您可以使用float而不是integer。