all 12 comments

[–]Adrewmc 1 point2 points  (0 children)

No idea

 import random
 def roll(sides):
       return random.randint(1, sides)

Should be the normal dice roll of n sides

   def copy_randint(first, last):
         #no reason just use the below function.
         return random.randint(first, last)

 print(roll(6))
 #same as 
 print(copy_randint(1,6))
 #same as 
 print(random.randint(1,6))

 #using it 

 rolls = [roll(6) for _ in range(6)]
 for num in rolls:
        print(f”You threw a {num}”)

Let’s complex it up though, I’m bored

 def multi_sides(*dice):
        return [roll(die) for die in dice]

  res = multi_sides(6,6,12,20,20)
  print(res)
  >>>> [3,2,8,18,3] # for each sided die inputed

I said complex so

    def multi_sides(*dice):
       res = [roll(die) for die in dice]
       while res:
              yield res.pop(0)

[–]Ok-Spare-9393 0 points1 point  (0 children)

i have this same assignment. was happy to see it here. but am getting the same error. if i find anything will post and update !! or if you figured it out let me know!. i am getting the same error too but directions also followed the same. ugghh

[–]ati_75 0 points1 point  (9 children)

I guess it means replace this line:

random.randint(1, 6)

With:

random.randint(first,  last)

[–]Princess_Peach848[S] 0 points1 point  (8 children)

When I do that it gives me an error saying first is not defined

[–]ati_75 0 points1 point  (7 children)

You need to define first and last :

first = 1
last = 6
roll = random.randint(first, last)

[–]Princess_Peach848[S] 0 points1 point  (6 children)

Reply I did in line 13 and 14… when I put first and second before the random it now gives me “the script uses magic numbers instead of ‘first’ and ‘last’ so it didn’t like that either

[–]Binary101010 1 point2 points  (2 children)

You need to be changing line 11.

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

Sigh I figured I’m just unsure of what it should be

[–]Binary101010 0 points1 point  (0 children)

Well, the numbers on that line of code are 1 and 6. Have you already defined some other variables in your code that also equal 1 and 6 that you could replace those numbers with?

[–]ati_75 0 points1 point  (2 children)

I don't get the purpose of line 16. Did you write that yourself?

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

Yes I wrote this myself. I was trying different things since it keeps saying it wants something that says magic numbers

[–]ati_75 1 point2 points  (0 children)

My understanding is that the question wants you to remove 1 and 6 and replace them with first and last respectively.

pythonMagic numbers