I've got some code here and I'm trying to review it to practice. The aim of the code is to read in a colour of a car and count up how many times that colour has been mentioned.
The code is below and it does work:
car = {}
color = input("Car: ")
while color:
if color not in car:
car[color] = 1
else:
car[color] = car[color] + 1
color = input("Car: ")
for x in car:
print("Cars that are", x, ":", car[x])
But I'm not sure what the following means or does:
for x in car:
print("Cars that are", x, ":", car[x])
I'm not sure about what phrases like for i in range:
or for x in cars:
mean.
I am new to programming. It would be appreciated is I could get an explanation about what they actually do in Python and what they mean as x wasn't assigned as a variable in the code.
Thanks.