someone can help me to solve that my problem? that problem is,
if iam input int (1,2,3,4,5,6,7,8,9,0) always error?
data = input()
array = list(data)
table = {" ":270,
"a":0,
"b":90,
"c":180,
"d":270,
"e":0,
"f":90,
"g":180,
"h":270,
"i":0,
"j":90,
"k":180,
"l":270,
"m":0,
"n":90,
"o":180,
"p":270,
"q":0,
"r":90,
"s":180,
"t":270,
"u":0,
"v":90,
"w":180,
"x":270,
"y":0,
"z":90,
"0":180,
"1":270,
"2":0,
"3":90,
"4":180,
"5":270,
"6":0,
"7":90,
"8":180,
"9":270,
"!":0,
"@":90,
"#":180,
"$":270,
"%":0,
"^":90,
"&":180,
"*":270,
"(":0,
")":90,
"-":180,
"_":270,}
for i in range(len(array)):
print(array[i])
print(("{["+array[i]+"]}").format(table))
Error at :
ex : if am input a#2
print(("{["+array[i]+"]}").format(table))
KeyError: 2
2vs string'2'? Try printingdataandarrayfirst to help you debug... Since we don't know what's in there we can't really help. See minimal reproducible example[element_index]the format specification language doesn't support. You can't quoteelement_indexand the format language checks to see if[element_index]is an integer and passes that before it uses it as a string, unfortunately you need it to be a string and that doesn't work. Ifarray[i]was say'*'it works fine.