#๐ I think I'm missing some logic
22 messages ยท Page 1 of 1 (latest)
@clever bay
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.
class User:
def __init__(self):
self.rank = -8
self.progress = 0
def inc_progress(self,activity_rank:int):
allowed_rank = [-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8]
if(activity_rank not in allowed_rank):
raise Exception("The Rank of the activity must be in the allowed ranks -8 to 8 excluding 0")
if(activity_rank == self.rank):
self.progress += 3
elif(activity_rank == self.rank-1):
self.progress +=1
elif(activity_rank > self.rank):
d = activity_rank - self.rank
self.progress += 10*d*d
while(self.progress >= 100):
self.progress -= 100
self.rank +=1
if self.rank == 0:
self.rank =1
elif self.rank == 9:
self.rank =8
(I would raise ValueError, not Exception (which is too vague). This kind of test is what ValueError is for.)
I think I'm missing some logic
(You don't need the brackets around the if conditions. Just if activity_rank not in allowed_rank: and so forth.)
Business Rules:
A user starts at rank -8 and can progress all the way to 8.
There is no 0 (zero) rank. The next rank after -1 is 1.
Users will complete activities. These activities also have ranks.
Each time the user completes a ranked activity the users rank progress is updated based off of the activity's rank
The progress earned from the completed activity is relative to what the user's current rank is compared to the rank of the activity
A user's rank progress starts off at zero, each time the progress reaches 100 the user's rank is upgraded to the next level
Any remaining progress earned while in the previous rank will be applied towards the next rank's progress (we don't throw any progress away). The exception is if there is no other rank left to progress towards (Once you reach rank 8 there is no more progression).
A user cannot progress beyond rank 8.
The only acceptable range of rank values is -8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8. Any other value should raise an error.
The progress is scored like so:
Completing an activity that is ranked the same as that of the user's will be worth 3 points
Completing an activity that is ranked one ranking lower than the user's will be worth 1 point
Any activities completed that are ranking 2 levels or more lower than the user's ranking will be ignored
Completing an activity ranked higher than the current user's rank will accelerate the rank progression. The greater the difference between rankings the more the progression will be increased. The formula is 10 * d * d where d equals the difference in ranking between the activity and the user.
what do you mean
Superficially this looks ok to me.
Does it not work?
This:
if (a == b):
can be written:
if a == b:
Brackets not needed.
I'm just so used to using it from java
Aye, and C. But not in Python. It's not ... wrong. Just unnecessary and looks visually noisy.
but can you look at my code and the prompt to see where I'm missing logic because i can not see where I'm missing the logic
I didn't see any missing logic. Are you getting incorrect output or something?
this is on Codewars and for the testcases its not passing all of them
You would need to show the failing tests. Or is it just a case of "Computer says no." ?
it don't give much information @brave finch
it does
Ye but when i go back to the logic I see that I'm adding everything it needs @vocal walrus
what do you thin?
think
This help channel has been closed. 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.