0
>>> def get_product(temp_pnr):
...     for i in range(0, len(temp_pnr), 2):
...             temp_pnr[i] = temp_pnr[i] * 2
...
>>> def sum_nums(temp_pnr):
...     sum = 0
...     for i in range(len(temp_pnr)):
...         sum = sum + (temp_pnr[i]//10) + (temp_pnr[i]%10)
...     return sum
...
>>> def check_cnr(sum):
...     big_num = ((sum//10) +1) * 10
...     cnr = (big_num - sum) % 10
...     return cnr
...
>>> def check_pnr(pnr):
...     controlnr = pnr[9]
...     temp_pnr = pnr
...     temp_pnr.pop(9)
...     print(pnr)
...     get_product(temp_pnr)
...     print(pnr)
...     return controlnr == check_cnr(sum_nums(temp_pnr))
...
>>> check_pnr([9, 5, 0, 9, 0, 8, 5, 5, 5, 2])
[9, 5, 0, 9, 0, 8, 5, 5, 5]
[18, 5, 0, 9, 0, 8, 10, 5, 10]
True

User gives a list "pnr" in the function check_pnr(pnr)
I save "pnr" in "temp_pnr" because I need to save "pnr" as it is
Then I call upon the "get_product(temp_pnr)" which alters "temp_pnr"
However, when checking the list "pnr " before and after calling "get_product(temp_pnr)" it differs
Why does it change even though I never use pnr in the function "get_product(temp_pnr)"?

Sandalguy
  • 1
  • 2
  • when you set temp_pnr = pnr you are creating two variable names that both point to the same list, so when you change temp_pnr you change the list they both point to. what you want to do is: temp_pnr = pnr.copy() to create two identical but separate lists – Portal Sep 14 '22 at 13:53

0 Answers0