So I’ve created a very basic program that rolls a dice a given number of times, and then displays who wins the game. I’ve tried to print the results as they go along with the roll #.
The problem I’m having is the output seems weirdly, an indecipherably (at least to my eyes) inconsistent (ie: sometimes it will show the roll #, sometimes it won’t.
Besides how much cleaner I could make this code, what am I doing that’s producing inconsistent roll # printing?
Code as follows:
import random
print("Let's play a little game!")
print("who is the most popular number on a die?")
print("Lets find out!")
def HighRolla():
ones = 0
twos = 0
threes = 0
fours = 0
fives = 0
sixes = 0
tries = 1
num_rolls = int(input("How many guesses?"))
for roll in range(num_rolls):
ran_num = random.randint(1, 6)
if ran_num == 1:
print(f"Roll {tries}: One for the ones")
ones += 1
elif ran_num == 2:
print("Roll {tries}: Two Two look at my shoe")
twos += 1
elif ran_num == 3:
print("Roll {tries}: THREE!! I'm free'")
threes += 1
elif ran_num == 4:
print("Roll {tries}: F0ar equals m0ar")
fours += 1
elif ran_num == 5:
print("Roll {tries}: Five five don't step in a bee hive'")
fives += 1
elif ran_num == 6:
print("Roll {tries}: Super Sixes - Yeharrrr!")
sixes += 1
rolls += 1
tries += 1
print(f"Final scores are: \n1: {ones}\n2: {twos}\n3: {threes}\n4: {fours}\n5: {fives}\n6: {sixes}")
HighRolla()’’’
fat the beginning of the string, so it prints the actual text{tries}instead of the value.rollsandtriesoutside the for-loop. Please post your actual code as it's currently written and don't change it.