Apr-07-2023, 11:29 PM
(This post was last modified: Apr-08-2023, 03:32 AM by deanhystad.)
Hey guys im new to coding doing a mature student diploma, im doing my 3rd project for the course and im getting results that don’t make sense. Please can someone tell me why the directory on the second pass is different? If you put this code in Python Tutor you will see that dirct_1 on the second pass starts in 10's when it should start at 1.
What am I trying to do?
Generate a directory containing for eg.. a:1 key and 1 as value, next would be b:2 with 2 as value and so on. So basically it’s a battleship grid reference.
Issue: On the second iteration the value starts at 10 and next run at 20.
Anny and all help welcome...
What am I trying to do?
Generate a directory containing for eg.. a:1 key and 1 as value, next would be b:2 with 2 as value and so on. So basically it’s a battleship grid reference.
Issue: On the second iteration the value starts at 10 and next run at 20.
Anny and all help welcome...
letters = [] dict_1 = {} def go(): for i in range(97, 107): letters.append(chr(i)) numbers = (list(range(1, 3))) print(numbers) final = [] i = 0 for i in (numbers): for content in (letters): num = content + ":" + str(i) alpha_num = num.strip() final.append(alpha_num) values = (list(range(1, 201))) dict_1 = dict(zip(final, values)) print(f"Final_zip = {final}") print(f"Values zip = {values}") print(f"Dict_1 = {dict_1}") go() go()