1

Есть код

n = input("n=")
lst=[2]
for i in range(3, n+1, 2):
    if (i > 10) and (i%10==5):
        continue
    for j in lst:
        if j*j-1 > i:
            lst.append(i)
            break
        if (i % j == 0):
            break
    else:
        lst.append(i)
print (lst)

Traceback (most recent call last): File "C:/Users/red.iguana/PycharmProjects/test/untitled/dsds.py", line 3, in <module>

for i in range(3, n+1, 2):

TypeError: must be str, not int

Выдает эту ошибку, помогите с программой, уверен будут еще ошибки после фикса этой. Python 3

1 ответ 1

5

Функция input() считывает строку, а вы с этой строкой пытаетесь работать как с числом. Преобразуйте строку в число вот так int(строка). То есть замените строчку

n = input("n=")

на

n = int(input("n="))

Больше ошибок вроде нету: Ideone

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.