#๐Ÿ”’ I think I'm missing some logic

22 messages ยท Page 1 of 1 (latest)

livid hingeBOT
#

@clever bay

Python help channel opened

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.

clever bay
#
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
brave finch
#

(I would raise ValueError, not Exception (which is too vague). This kind of test is what ValueError is for.)

clever bay
#

I think I'm missing some logic

brave finch
#

(You don't need the brackets around the if conditions. Just if activity_rank not in allowed_rank: and so forth.)

clever bay
#

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.

brave finch
#

Superficially this looks ok to me.
Does it not work?

brave finch
clever bay
#

I'm just so used to using it from java

brave finch
#

Aye, and C. But not in Python. It's not ... wrong. Just unnecessary and looks visually noisy.

clever bay
#

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

brave finch
#

I didn't see any missing logic. Are you getting incorrect output or something?

clever bay
#

this is on Codewars and for the testcases its not passing all of them

brave finch
#

You would need to show the failing tests. Or is it just a case of "Computer says no." ?

clever bay
#

it don't give much information @brave finch

vocal walrus
#

it does

clever bay
#

Ye but when i go back to the logic I see that I'm adding everything it needs @vocal walrus

livid hingeBOT
#
Python help channel closed using Discord native close action

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.