-1
n=[0]*365
s=0
s1=1
s2=2
s3=3
s4=4
s5=5
s6=6
for i in range(len(n)):
    n[i]=4+1
    s=s+7
    s1=s1+7
    s2=s2+7
    s3=s3+7
    s4=s4+7
    s5=s5+7
    s6=s6+7
    if n[i]==s:
        n[i]=0
    elif n[i]==s1:
        n[i]=1
    elif n[i]==s2:
        n[i]=2
    elif n[i]==s3:
        n[i]=3
    elif n[i]==s4:
        n[i]=4
    elif n[i]==s5:
        n[i]=5
    elif n[i]==s6:
        n[i]=6

Hey everyone here is my code i need to imput which number in row in array it is and it needs print out the number like if i input 300 it needs to output the 300th number in the list I have tried using print(n[input()] but that obvioslly didnt work can you please help me

TurtleSam
  • 29
  • 5
  • FWIW, whenever you have variables numbered sequentially (`s`, `s1`, `s2` etc.), that's a sign there's a simpler algorithm in which you could just use a list and loop over the list, instead of typing all this out one by one… – deceze Apr 26 '22 at 08:37

1 Answers1

0

It is because input returns a string. The following should work:

print(n[int(input())])

However, note that this will fail if you input something else than a number as python will fail in the int conversion.

leleogere
  • 908
  • 2
  • 15