+1

Repeat the Die Roll n times and suggest which number between 1 and 6 fall maximum number of times.

I don't understand where I am going. Please help! Below is my code: import random f1=0 f2=0 f3=0 f4=0 f5=0 f6=0 n=int(input()) for i in range(0,n): def die(n): if die==1: f1+=1 elif die==2: f2+=1 elif die==3: f3+=1 elif die==4: f4+=1 elif die==5: f5+=1 else: f6+=1 x=random.randint(1,6) die(x) print("die1: " +f1+"die2: " +f2+"die3: " +f3+ "die4: " +f4+"die5: " +f5+"die6: " +f6)

1/24/2020 4:15:26 PM

Prithvi

2 Answers

New Answer

+4

... allow me to introduce some changes to your code. import random # instead of using separate variables as counter, let's use a list! counter = [0,0,0,0,0,0] n = int(input()) for i in range(0,n): counter[random.randint(1,6)-1]+=1 # we find the max counter mode = max(counter) # and we find which number the max counter belongs to max_roll = counter.index(mode)+1 print(max_roll) # The problem with this code though, is that it doesn't care if there are two max rolls.

0

Fermi, wow! Thank you.