0

this is my code:

r = int

for q in range(0 + (casovaJednotka - celkovaCasovaJednotka), casovaJednotka + 1):
    r[q] = q + 1
    q = q + 1

for i in range(casovaJednotka, 0, -1):
    for w in range(0 + (casovaJednotka - celkovaCasovaJednotka), casovaJednotka):
        if r[w] != i:
            print(q[w])
        if casovaJednotka - 1 == w:
            print("0\n")

and this is the problem:

if r[w] != i:
TypeError: 'type' object is not subscriptable

and also it has the same problem with

r[q] = q + 1

1 Answers1

1

In your code, you are initializing the r variable as an int object. By looking at your code, I can assume that you want r to be an array of integers. So instead of defining r=int, you can do this.

r=[]

OR

r = list(range(10)) #initialize a list of size 10 items 

To know more about what is TyprError and Python throw this error (Python Error "TypeError: 'type' object is not subscriptable), you can read this article, here, I have elaborate on this error in detail.

Vinay Khatri
  • 312
  • 1
  • 8
  • if I inicialise r = [] I still have porblem with q – Christofer Kiňo Aug 30 '22 at 10:48
  • for r=[], you need to use r.append(q + 1) but for r= list(range(10)) you can use r[q]=q + 1 – Vinay Khatri Aug 30 '22 at 10:53
  • now I have problem with q in this: for i in range(casovaJednotka, 0, -1): for w in range(0 + (casovaJednotka - celkovaCasovaJednotka), casovaJednotka): if r[w] != i: print(q[w]) if casovaJednotka - 1 == w: print("0\n") it do not want print q[w] – Christofer Kiňo Aug 30 '22 at 11:21
  • q[w] is an illegal statement becaue q is an integer object. You first need to convert it into string to perform the indexing operation use this statement int(str(q)[w]) – Vinay Khatri Aug 31 '22 at 05:52