The Student Room Group

i need my program to print the score of 2 dice added together five times

import random

def main():
username = input('username')
password = input('password')
if username == 'brandon' and password == 'pass':
print('welcome')
random_dice()
else:
print('nah try again')
main()

def random_dice():
roledice = input ('when ready to roledice type start')
if roledice == 'start':
print('roling dice 2 dice ')
die1 = random.randint(1,6)
die2 = random.randint(1,6)
score = print(die1+die2)
else:
print('tryagain')

if __name__ == "__main__":
main()

for i in range(1,5):
random_dice()
Reply 1
You're printing the values added as a single value. Can't you convert die1 and die2 to a string? Or use a %d operator so you can print('%d %d', die1, die2) ...?

What the hell language even is this?
you could do it as vectors

import numpy as np

die_one_vec = np.random.randint(1,7, size=5)
die_two_vec = np.random.randint(1,7, size=5)
addi_dice_vec = die_one_vec + die_two_vec

print('first die', die_one_vec)
print('second die', die_two_vec)
print('added dice', addi_dice_vec)

--- output ----
first die [3 5 2 5 4]
second die [1 6 3 5 2]
added dice [ 4 11 5 10 6]
(edited 5 years ago)
what do you mean what language is this
Original post by brandongiles55
what do you mean what language is this

Original post by Tootles
You're printing the values added as a single value. Can't you convert die1 and die2 to a string? Or use a %d operator so you can print('%d %d', die1, die2) ...?

What the hell language even is this?

it's Python

Quick Reply

Latest

Trending

Trending