Reputation: 15
Here is the code:
num1 = print(random.choice(range(1,7)))
num2 = print(random.choice(range(1,7)))
I need to add num1 and num2:
total = num1 + num2
Gives an error
Upvotes: 1
Views: 31
Reputation: 405675
You're getting an error because you're assigning the result of print
to a variable, and print
returns None
, not the value printed. (The error comes later, when you try to add these two NoneType
values together.)
Change your code to assign the random values to your variables, then print those and add them together.
num1 = random.choice(range(1,7))
num2 = random.choice(range(1,7))
Upvotes: 2
Reputation: 7206
Return Value from print():
It doesn't return any value; returns None.
import random
num1 = random.choice(range(1,7)) # num1 = None
num2 = random.choice(range(1,7)) # num2 = None
total = num1 + num2
print (total)
Upvotes: 0