The problem i m facing is that when the input is (9812, 2), when the remove() function is called on the list, it deletes the first instance of "2" on index 2 while i want to remove the one on index 4( provided the ss pls check) . I can't also think of any alternate solution to this kata/problem kindly help
#๐ How do i fix my code
82 messages ยท Page 1 of 1 (latest)
@gentle ridge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
you'll have better luck here if you post your code as text, not a screenshot
alright!
def digitwise_addition(n, k):
x = str(n)
sep = list(x)
z = 0
n = 0
for a in range(0,k):
for i in sep:
z = int(i)
z += 1
z = str(z)
sep.insert(n, z)
sep.remove(i)
n += 1
if a > 0:
n = 0
y = ''.join(sep)
return len(y)
ah I think you asked this question earlier
yea but got no replies :(
where can I find a clear and precise definition of "digitwise addition"?
that doesn't require me to squint at a screenshot? ๐
here u go
that's a 500 error ๐ฆ
https://www.codewars.com/kata/663e0eccecb2d0a12da51f84/ looks oK though
yes this is the one !
omg you're doin 5 kyu!?
ok, now what's your question?
well good luck with that
i m trying my level best
The problem i m facing is that when the input is (9812, 2), when the remove() function is called on the list, it deletes the first instance of "2" on index 2 while i want to remove the one on index 4( provided the ss pls check) . I can't also think of any alternate solution to this kata/problem kindly help
my brain kept frying up on 5 kyus... Stuck at 6 kyu. Best of luck! ๐
>>> digitwise_addition(9999, 1)
y='10101010'
8
>>> digitwise_addition(9999, 2)
y='12111011'
8
>>>
``` that second one looks wrong
this is my first time trying a 5 kyu question and my pain is the same ๐ญ
idk about that ๐
yes
I must say, your variable names are about as bad as they can possibly be. I'm studying your code trying to figure out wtf they mean. I'm pretty sure that sep should be renamed to digits, but that's as far as I've gotten.
๐ญ i m very bad at naming variables sorry
I'm sorry, but your code is so confusing that I can't suggest any way to fix it. I can show you how I'd do it, if you're interested.
please tell
btw you can visualise my code
!e
def mine(n, k):
while k > 0:
digits = [int(d) for d in str(n)]
incremented = [d + 1 for d in digits]
n = int("".join([str(n) for n in incremented]))
print(f"{digits=} {incremented=} {n=}")
k -= 1
return len(str(n))
print(mine(9812, 2))
in pythontutor
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | digits=[9, 8, 1, 2] incremented=[10, 9, 2, 3] n=10923
002 | digits=[1, 0, 9, 2, 3] incremented=[2, 1, 10, 3, 4] n=211034
003 | 6
I have no idea what that means
๐คท
and visualise it
I can also just run it myself. That web site won't help.
it gives step by step explanation that''s what i was tryna say
I know how python works; I don't need a step-by-step explanation.
no man you took it wrong , i thought you didn't understand my code because of how badly i named them so i thought you could understand it better on the site
Unless that site is run by a genius who can read your mind, and explain how each step of the code implements your solution to this problem, I doubt it'll be useful to me, in understanding how your code implements your solution to the problem. Let's forget it for now.
in your code .remove is not always doing what you think it does. I would work with the list index then you don't have to insert or remove.
pls guide me on how will you work with the list index ๐
instead of for i in sep:
use for i in range(len(sep))
then use sep[i] where you have i to get the value in that index
replace insert/remove with sep[i] = z
you will have to use .join then turn that into a list again after each inside loop.
this last step takes care of the 9s that turned into 10s
List indexing lets you get and change a member of a list
Remember list indexing starts a 0 but you don't have to worry about that here as range also starts at 0
i made the changes as u said till here
can u pls re explain the last step?
indent y= ... one level to join the strings into one string. Then sep=list(y) on the next line to make the digits a list again befor runing the outer loop again.
OK how did that work?
it didn't work :(
Error or wrong result?
z=int(i) needs to be z=int(sep[i])
which gets the value of list at that index
tysmm it worked ๐
i also get it where it was wrong
thank u
but i m stuck at one part now and i rly dont know what that means
Still here
Timed out after 12 seconds. It said it could be server problem. Did you run again and get the same error?
i did... it gave the same error :(
it might be related to this thing? I pretty much ignored this part but i guess it has some role too
I just Googled and it looks like you need to do it with math to get faster results but it is above my math level.
https://stackoverflow.com/questions/78830347/digitwise-addition-exceed-limit-if-exceeded-code-time-out#:~:text=Digitwise addition is a special,over to the next digit.
Or that which I don't get either.
same ๐
so i spent half the day just to not complete this kata ๐ญ
But I think you learned a few things. Take care.
yes !! thank you for the help once again ๐
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.