Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Man, thx for showing me the other way to solve this problem. The way you use enumerate is genius!
I agree. Replace "/" with "//" and this solution is pretty close to perfect.
Nice
SHIT! So smart! I was wondering how the p+i didn't make it start from 0. Then I remembered the first one will make p default to 1 since p^i is n^0. I am beginning to understand enumerate() more and more
thanks
aw I was so over thinking this
type casting should have been done in the return statement, as it may not result any remainder, but the result of the division d always be a float. # Just a precaution
I agree with both, but for people who are still learning python as they go, a little naming readability on the solution goes a long way.
i and c are quite straightforward though?
i = index, which has always been a convention
c = character, which is quite obvious when you look at str(n)
It isn't as big of a deal as you make it out to be, this is about problem solving, not about following pep8 or any naming conventions.
If it was a software then I would 100% agree with you.
This is 1:1 with mine but this is not as readable. I think we should stop giving "Best Practices" to people that use one letter variable names like n, p, s, i... instead of number, power, sum ("result" would be better), index...
I flashed with this brief resolution! Tks!!
Enumerate also automatically iterates through each of the digits, so you don't need to cast the number to a string, and loop through each letter (like I did lol).
I did:
str_number = str(number)
digit_list = []
for digit in range(0, len(str_number)):
digit_list.append(int(str_number[digit]))
and then enumerated through that digit_list, but the "enumerate(str(n))" in
for i, c in enumerate(str(n)):
gives you access to each digit in the number as a string in a much more elegant way.
You can also start enumerating from any int you want
in this case it would be
enumerate(str(n),p)
I recommend always to check the documentation whenever you see something new
I'm new too starts about a week ago, for what I understand in enumerate the first i is index starting from 0. Each time it iterates the i will +1. So by using enumerate we have a default i that starts at 0 and +1 everytime. Since the i comes with the enumerate function itself thus we don't need to create another variable to increase p.
so s += pow(int(c),p+i), p+i = 0 at the first time which is p itself, then p+1, p+2 ....
Loading more items...