M
M
Mihail Starygin2017-07-28 00:54:23
css
Mihail Starygin, 2017-07-28 00:54:23

I can't figure out why the error is coming out in python code!?

This code translates nicely from 10th to 2nd numeral system, just like in the code the resulting number belongs to the class (even when using the type() method). In the future, I have to work with strings and an error came up during the test, help me deal with it, thank you in advance,

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
ost = 0
dba =''
dbb =''
dbc =''
maxi = 0

def translatedb(st1, sto, sts): # <------ Начало метода перевода
  while(st1 >= 1):
    sto = st1 - (st1//2 * 2)
    sts =str(sts + str(sto))
    st1 = st1 // 2 
  sts = sts[::-1]
  print(sts)# Метод переводит в двоичную систему
                         #      _____________________________
translatedb(a, ost, dba) # ---|                               |
translatedb(b, ost, dbb) # ---| Вызов для трех чисел!!!!!!!!  |
translatedb(c, ost, dbc) # ---|_______________________________|

a = len(dba)
b = len(dbb)
c = len(dbc)

print(dbb[1])

Output result:
76 85 104 <------ Keyboard
input 1001100
1010101
1101000
Traceback (most recent call last):
File "python", line 27, in
IndexError: string index out of range

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Samuello, 2019-02-24
@Samuello

Watch this video: link

C
clopik, 2017-07-28
@clopik

In a function, arguments are passed by reference, but changing them inside a function does not always change the passed object. If instances of classes, lists, dictionaries (mutable objects) are passed, then the change in their state will be reflected in the original object. If numbers, strings or tuples (immutable objects) are passed to the function, then when you try to change their value in the function body, a new object of the same type will be created, but already locally, and the object passed outside will not be changed. In your case, dba, dbb, and dbc will be equal to the empty string, just like before the call to translatedb.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question