L
L
link_vrb2021-07-10 16:17:16
Python
link_vrb, 2021-07-10 16:17:16

How to solve the problem in code?

from threading import Thread

colours = []
th = []
por = '123'
pora = {1: 'зеленым', 2: 'желтым', 3: 'красным'}
por1 = {}
numsv = int(input('Кол-во светофоров --> '))
print('\n\t1 --> зеленый\n\t2 --> желтый\n\t3 --> красный')
for i in range(int(numsv)):
    colours.append(int(input('> ')))


def prino(colour, numsvet):
    print('Светофор номер {} зажегся {} цветом'.format(numsvet, colour))


def svetofor(col, numsv):
    por1[numsv] = por.replace(str(col), '')
    for i in por1[numsv]:
        prino(pora[i], numsv)
    while True:
        for i in por:
            prino(pora[i], numsv)


def svets(num):
    for i in range(int(num)):
        Thread(target=svetofor, args=(i+1, i,)).start()


svets(numsv)

this is the code and here is the error:
prino(pora[i], numsv)
KeyError: '2'

she is not the only one but the first

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-07-10
@link_vrb

You have numeric keys, and a string porain a variable .i

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question