(Python3) No Dice? No Problem - Help with the task | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

(Python3) No Dice? No Problem - Help with the task

I've got a problem to solve that task. I'm a little bit confused about which concepts I must use to solve the problem. I've tried to solve it in two diferent ways, which I paste below. Task Two friends want to play backgammon, but have lost the dice. Create a program to replace the dice. When the program is run, it should roll the dice and output the result of each die. Use random.randint() function to generate random values in the range of 1 to 6 for each dice. 1) import random random.seed(int(input())) #please don't touch this lane def dice1(random.seed) for i in range(6) return random.randint(1,7) def dice2(random.seed) for i in range (6) return random.randint(1,7) print(dice1) print(dice2) 2) import random random.seed(int(input())) #please don't touch this lane for i in range(6): dice1 = random.randint(1, 7) dice2 = random.randint(1, 7) print(dice1) print(dice2) Thank you in advance!

5th May 2021, 3:03 PM
Bruno Pereira de Carvalho
Bruno Pereira de Carvalho - avatar
3 Answers
0
I might be misunderstanding the task, but i believe that this could be much simpler. A random.randint function can be used to define two dice, and then can be just printed, like so: import random dice1=random.randint(1,7) dice2=random.randint(1,7) print(dice1) print(dice2)
5th May 2021, 3:18 PM
Kamil Hamid
Kamil Hamid - avatar
+ 1
#2 should work 👍 Put it in the code playground & run it
5th May 2021, 3:20 PM
Steven M
Steven M - avatar
+ 1
why do you use 7 for randint's second argument. a dice has six faces and if you use randint(1,7) in that case 7 included. but it should be from 1 to 6. am I wrong...
6th Sep 2021, 7:31 PM
Bekir
Bekir - avatar