Hello people, a bit of Python help required.
It is a basic program, however I am a bit stuck.
I want to store basketball player information, and the things I want to store are Player name and Player height.
Also, I want to be able to iterate using loops through that list, so therefore I made a list of dictionaries to achieve that?I am not sure if everything is correct?
The code below
print("Basketball players ranker")
p_num = int(2)
player_info = [{
"Name":[],
"height":[]
}]
for i in range(p_num):
print("please enter player name")
player_name = input()
print("please enter player height")
player_height = int(input())
player_info.append(["Name"].append(player_name))
player_info.append(["height"].append(player_height))
counter = int(0)
print("so we got the folowing info")
for i in player_info:
print(player_info[counter].get("Name"))
print(player_info[counter].get("height"))
counter +=1
The output example below
Basketball players ranker
please enter player name
pl1
please enter player hight
10
please enter player name
pl2
please enter player hight
20
so we got the folowing info
[]
[]
Traceback (most recent call last):
File "d:\python\projects\python_learning\python-exirsizes\x3.py", line 22, in <module>
print(player_info[counter].get("Name"))
AttributeError: 'NoneType' object has no attribute 'get'
PS D:\python\projects\python_learning\python-exirsizes>
I think from my code above you should understand what I am trying to achieve and if I am totally wrong please provide me the corrected code if you can.
Thanks very much for your help.