0

Obviously I am new to programming and Python so I am trying to learn. Here is my question below I am trying to answer:

“We will pass in 2 values, X and Y. You should calculate X^y and output the final result” what you see below is what I was provided. I believe I am to use a nested loop to calculate it.

import sys
X = int(sys.argv[1])
Y = int(sys.argv[2])
yoMama
  • 11
  • 1
  • 4
  • 2
    what is the error message? – eyllanesc Jan 27 '19 at 02:47
  • 1
    When asking about code that produces an Exception you should always include the complete Traceback in the question. Copy the Traceback and paste it in the question, then format it as code (select it and type ctrl-k) – wwii Jan 27 '19 at 02:49
  • There is a list of numeric operations in the [Numeric Types](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) section of the docs. – wwii Jan 27 '19 at 02:54
  • Possible duplicate of [Python and Powers Math](https://stackoverflow.com/questions/12043913/python-and-powers-math) – Fynn Becker Jan 27 '19 at 02:55
  • `...I get an error.` you need to be specific about how/why your solution is deficient. Without something more cocrete there is a chance it may be closed as *off-topic* - https://stackoverflow.com/help/on-topic – wwii Jan 27 '19 at 03:00

3 Answers3

2

Try X ** Y, unless you have some other requirement (like writing it by hand).

Kevin Ji
  • 10,479
  • 4
  • 40
  • 63
0

To raise X to the Y in python, you want to use the exponentiation ** operator: this should do it: in terminal:

python

>>> 5**4
>>> 625
dsb4k8
  • 61
  • 3
0

You can also use function for powering:

 math.pow(x, y)
fuNcti0n
  • 177
  • 1
  • 11