Function involved: for in int () Enumerate(return value does not accept string type after adding ":")
1i = ["Computer","Water Bottle","Mouse","keyboard"]2 forKey,zifuinchEnumerate (i):#key equals enumerate auto-assigned zero-based number3 Print(Key,zifu)4QQ = input ("Please enter the desired product:")5INP_NM =Int (QQ)6 Print(I[INP_NM])
1 i = ["Computer","Water Bottle","Mouse","keyboard"]2 forKey,zifuinchEnumerate (i,1):#key equals enumerate automatically assigned a number starting from 1, 1 can be arbitrarily modified. 3Print(Key,zifu)4 QQ = input ("Please enter the desired product:")5 inp_nm =Int (QQ)6Print(I[INP_NM])
The above, although the enumerate starting from 1, but in essence, from the beginning of 0 to assign value
1 i = ["Computer","Water Bottle","Mouse","keyboard"]2 forKey,zifuinchEnumerate (i,1):#key equals enumerate automatically assigned a number starting from 1, 1 can be arbitrarily modified. 3Print(Key,zifu)4 QQ = input ("Please enter the desired product:")5 inp_nm =Int (QQ)6Print(I[inp_nm-1])
In line 6th Inp_nm minus 1,ok.
Python automatically adds serial numbers to items.