I m create a program in Python 3 and this Error show "TypeError : unsupported operand type(s) for ** or pow(): 'str' and 'int' " | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

I m create a program in Python 3 and this Error show "TypeError : unsupported operand type(s) for ** or pow(): 'str' and 'int' "

Solve this error Python3

14th Apr 2020, 2:55 PM
Rahul Singh
Rahul Singh - avatar
7 Respostas
+ 2
Plz try To put you code Rahul Singh
14th Apr 2020, 3:09 PM
iren yeger
iren yeger - avatar
+ 1
Looks like youre trying to add a string with a number or multiply a number by a string. Put some checks in your code print(type(problem_variable) That will return the type. and if its an integer but you want it to be a string so no type error... str(problem_variable) going to need to see the code though
14th Apr 2020, 3:16 PM
Slick
Slick - avatar
0
this my Code One Case P_hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F' P = int(P_hex, 16) compressed_key_hex = input('Enter Your Compressed Public Key: ') x_hex = compressed_key_hex[2:66] x = int(x_hex, 16) prefix = compressed_key_hex[0:2] y_square = (pow(x, 3, P) + 7) % P y_square_square_root = pow(y_square, (P+1)//4, P) if (prefix == "02" and y_square_square_root & 1) or (prefix == "03" and not y_square_square_root & 1): y = (-y_square_square_root) % P else: y = y_square_square_root computed_y_hex = format(y, '064x') computed_uncompressed_key = "04" + x_hex + computed_y_hex print("X #", compressed_key_hex) print("Y #", computed_uncompressed_key) p = 115792089237316195423570985008687907853269984665640564039457584007908834671663 a = 0 b = 7 x = int(x_hex, 16) s = pow(3*x**2) + a print("S #", s) and this error show TypeError: pow expected at least 2 arguments, got 1
15th Apr 2020, 11:45 AM
Rahul Singh
Rahul Singh - avatar
0
is that the full error code? It looks like its catching your second to last line. s = pow(3*x**2) + a Try, s = pow(3*x, x**2) + a The error is just saying pow should have one more argument. The comma should help with that error. For each case above except in the last one, the pow (function or method) can be seen with more than 1 parameter.
15th Apr 2020, 12:04 PM
Slick
Slick - avatar
0
This My code 2 case P_hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F' P = int(P_hex, 16) compressed_key_hex = input('Enter Your Compressed Public Key: ') x_hex = compressed_key_hex[2:66] x = int(x_hex, 16) prefix = compressed_key_hex[0:2] y_square = (pow(x, 3, P) + 7) % P y_square_square_root = pow(y_square, (P+1)//4, P) if (prefix == "02" and y_square_square_root & 1) or (prefix == "03" and not y_square_square_root & 1): y = (-y_square_square_root) % P else: y = y_square_square_root computed_y_hex = format(y, '064x') computed_uncompressed_key = "04" + x_hex + computed_y_hex print("X #", compressed_key_hex) print("Y #", computed_uncompressed_key) p = 115792089237316195423570985008687907853269984665640564039457584007908834671663 a = 0 b = 7 x = int(x_hex, 16) x1 = str(x) s = pow(3*x1**2) + a print("S #", s) Error show : TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
15th Apr 2020, 12:05 PM
Rahul Singh
Rahul Singh - avatar
0
Well there it is. Youre either trying to multiply a string by itself or multiply a number by a string and that dont work. Find your string, "x1" and convert it to an integer if possible using int(). Or just dont change "x1" to a string in the first place so instead of using "x1" just use "x"
15th Apr 2020, 12:09 PM
Slick
Slick - avatar
0
Ok I m try
15th Apr 2020, 2:05 PM
Rahul Singh
Rahul Singh - avatar