I'm getting a syntax error on line 26 when trying to read user input. Also, python is not identifying \n as a newline and instead is outputting it as if it were a raw string. I don't see anything wrong with my code, but maybe I'm missing something. Thank you in advance for any help!
'''
program that calculates the number of times
the sum of two randomly rolled dice equals each
each possible value given a read number of rolls.
outputs a histogram of rolls
program repeats until user enters a
negative number of rolls.
'''
import random
num_twos = 0
num_threes = 0
num_fours = 0
num_fives = 0
num_sixs = 0
num_sevens = 0
num_eights = 0
num_nines = 0
num_tens = 0
num_elevens = 0
num_twelves = 0
num_rolls = int(input('Enter number of rolls:\n')
histogram_char = input('Choose a symbol to represent data:\n')
if num_rolls >= 1:
for i in range(num_rolls):
die1 = random.randint(1,6)
die2 = random.randint(1,6)
roll_total = die1 + die2
#count number of each possible roll
if roll_total == 2:
num_twos += 1
if roll_total == 3:
num_threes += 1
if roll_total == 4:
num_fours += 1
if roll_total == 5:
num_fives += 1
if roll_total == 6:
num_sixs += 1
if roll_total == 7:
num_sevens += 1
if roll_total == 8:
num_eights += 1
if roll_total == 9:
num_nines += 1
if roll_total == 10:
num_tens += 1
if roll_total == 11:
num_elevens += 1
if roll_total == 12:
num_twelves += 1
print('2s: {}'.format(num_twos*histogram_char))
#FIXME: continue histogram for numbers 3 through 12
num_rolls = int(input('Enter number of rolls:\n')
else:
print('{} is an invalid number of rolls, try again.')
Aucun commentaire:
Enregistrer un commentaire