-3
num1 = print(random.randint(0,9))
num2 = print(random.randint(0,9))
print(num1 ** num2)

When ever I try to run this in python I receive the error

TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'NoneType'

Anyone know the issue im having here and how i can go about fixing it?

CamO
  • 7
  • 3

3 Answers3

1

The issue that you are using the "print" - function which returns "None" as value when you try to assign the numbers to their variables.

In order to fix this issue, you simply have to remove the print-statements or put them in another place, so that your code looks like this:

num1 = random.randint(0,9)
num2 = random.randint(0,9)
print(num1 ** num2)

Take care

Bialomazur
  • 1,122
  • 2
  • 7
  • 18
1

Remove the 'print()' that you have putted in "num1 = print(random.randint(0,9))" and "num2 = print(random.randint(0,9))", it should fix the issue.

Also you should change the last line to print(str(num1 ** num2)) instead of print(num1 ** num2) :D

  • that second suggestion is less helpful; python automatically converts `print` arguments to strings as needed – Sam Mason Oct 12 '20 at 08:49
0

Try this,

num1 = random.randint(0, 9)
num2 = random.randint(0, 9)
print(num1 ** num2)

In your code, you are using print to get the value, but print statement does not return the value (as you wanted in your code) i.e. the return-type of print is None.

AnupaM
  • 187
  • 2
  • 2
  • 8