Python Forum
Generalized Dice refactoring
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generalized Dice refactoring
#2
(Feb-04-2019, 09:20 PM)Beginner_coder123 Wrote: number = random.randint(0,len(die)-1)
This is the same, and clearer: number = random.randint(len(die))
But this is even clearer: number = random.choice(die)

(Feb-04-2019, 09:20 PM)Beginner_coder123 Wrote: ending_conditions = ['stop','Stop','quit','Quit']
If you call .lower() on the input, you only need ending_conditions = ['stop', 'quit']. As an added bonus, you also properly handle weird things like "sToP", or "QUIT".

(Feb-04-2019, 09:20 PM)Beginner_coder123 Wrote: while end == False:
That's kind of gross, and would look nicer as while not end:.

(Feb-04-2019, 09:20 PM)Beginner_coder123 Wrote: if not(inpu in ending_conditions):
I'd prefer to see the "not" next to the "in", like such: if inpu not in ending_conditions:

The functions quantitymatrix and deeper are the same. One of them can just be deleted, and you can call the other instead.

Aside from that, what is it you're trying to refactor?
Reply


Messages In This Thread
Generalized Dice refactoring - by Beginner_coder123 - Feb-04-2019, 09:20 PM
RE: Generalized Dice refactoring - by nilamo - Feb-04-2019, 10:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  refactoring kerzol81 8 3,520 Nov-02-2019, 09:49 AM
Last Post: Gribouillis
  Python Connect 4 refactoring Beginner_coder123 6 3,801 Oct-29-2018, 05:30 PM
Last Post: Beginner_coder123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020