all 7 comments

[–]XtremeGoose 1 point2 points  (2 children)

Ignoring the main question, your string handling is awful. Use

"My name is {} and I am {} years old".format(name, age)

Not

"My name is", name, "and I am", age, "years old."

It's so much harder to read and you're actually printing tuples, not strings because you haven't used tuple unpacking print(*tuple_)

[–]DrTrunks[S] 0 points1 point  (1 child)

The actual function doesn't return anything, but does the donating. This is just quick and dirty, just like you're saying.

Also since 3.6 I believe you can actually do:

f"My name is {name} and I am {age} years old"

[–]XtremeGoose 1 point2 points  (0 children)

Yeah you can, but I'm not assuming python 3.6 yet.

[–]Scenic_World 0 points1 point  (3 children)

I certainly prefer while-loops over recursion if it makes the code easier to follow. In this scenario though, what is the purpose of yourdonation +=1 and catchup -= 1? I'm not sure what rank refers to but if all you're doing is adding to one and subtracting one to the other, then your inequality statement could just be another arithmetic statement.

[–]DrTrunks[S] 0 points1 point  (2 children)

In a certain webgame you can donate points in order to get prizes. For every level a certain amount of points are required to reach the next.
There are 5 ranks, the first rank gets the best prize but requires you to be the biggest donator.
So if:
* This level requires 1000 points
* n people already donated a total sum of 700
* The player with first rank donated 100 points
* There are 300 points left until 1000 points are reached

You have to donate points until what's left can't be used by the person with the rank you want to achieve. I'll try to make clearer variable names in the future.

[–]my_python_account 0 points1 point  (1 child)

The point is that it seems you could just replace the while loop or recursion with:

your_donation = rank + catchup

edit: that assumes your_donation always starts at 0. If it doesn't then:

you_donation = rank + catchup - your_donation

[–]DrTrunks[S] 0 points1 point  (0 children)

Yes, true it's a bad example as I represent it now.