-2

Sage programing

write a sequence of commands that will randomly generate an integer a between 1 and 6 and another integer between 1 and 6 and compute the following:

(a)the sum of the two integers as an integer.

(b) the sum of the two integers as a string.

(c) a string representing the value of a plus b (i.e if a=2 and b=3, the string that should returned is '2+3'

ADAM
  • 105
  • 1
  • 7
  • 1
    I'm sorry, but we are not here to do your programming assignments. What did you try? Where did you get stuck? – Martin Tournoij Aug 27 '16 at 15:51
  • Mandatory reading: [ask], [MCVE], [How do I ask and answer homework questions?](http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions) – Łukasz Rogalski Aug 27 '16 at 17:16

1 Answers1

0

that prints all values required:

import random

a = random.randint(1,6)
b = random.randint(1,6)

print(a+b)       # sum
print(str(a+b))  # sum as string
print(str(a)+"+"+str(b)) # expression

note that 2 first printed statements are identical. Only the type change (int or string).

output:

6
6
4+2
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219