954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Question on pow() function error

I'm typing the code:

import cmath
import math
print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1" pow(2,3) pow(2,3,1)


and I'm getting this error:

File "sample2.py", line 26
print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1" pow(2,3) pow(2,3,1)
^
SyntaxError: invalid syntax


Why is this invalid syntax?

Cenchrus
Newbie Poster
19 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

You are missing the comma between values.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

I'm typing the code:

Python Syntax (Toggle Plain Text)
import cmath
import math
print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1" pow(2,3) , pow(2,3,1)

and I'm getting this error:

File "sample2.py", line 26
print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1" pow(2,3) , pow(2,3,1)
^
SyntaxError: invalid syntax


I put the comma between the values pow(2,3) , pow(2,3,1). and it said the same thing

Cenchrus
Newbie Poster
19 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

For python 2 and 3,i think you use pyhon 3 because you get error on print.

#Python 2.7
>>> print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1", pow(2,3), pow(2,3,1)
pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1 8 0
#Python 3
>>> print(r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1", pow(2,3), pow(2,3,1))
pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1 8 0
>>> help(pow)
Help on built-in function pow in module builtins:

pow(...)
    pow(x, y[, z]) -> number
    
    With two arguments, equivalent to x**y.  With three arguments,
    equivalent to (x**y) % z, but may be more efficient (e.g. for longs).

>>>
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
 

pow is a function in the "math" program

import math
print r"pow(2,3) returns 2^3-->", math.pow(2,3)
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: