我为 uri 在线法官编写此代码(问题编号 1036)...这是 Bhaskara 公式...
import cmath
A,B,C=input().split()
A = float(A)
B = float(B)
C = float(C)
D = (B*B)-(4*A*C)
if((D== -D)|(A==0)):
print("Impossivel calcular")
else:
T = cmath.sqrt(D)
x1 = (-B+T)/(2*A)
x2 = (-B-T)/(2*A)
print("R1 = %.5f" %x1)
print("R2 = %.5f" %x2)
Run Code Online (Sandbox Code Playgroud)
但是当我提交这个程序时...发生了运行时错误...
Traceback (most recent call last): File "Main.py", line 14, in
print("R1 = %.5f" %x1)
TypeError: can't convert complex to float
Command exited with non-zero status (1)
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题。
我想在for循环中使用浮点数。所以我写了这段代码:
k=1
for i in range(0,3,0.2):
for j in range(k,k+3,1):
print("I= %i J=%i"%(i,j))
k=k+0.2
Run Code Online (Sandbox Code Playgroud)
但出现了以下错误:
Traceback (most recent call last):
File "C:\Users\Md. Rakibul Islam\Desktop\URI practise.py", line 2, in <module>
for i in range(0,3,0.2):
TypeError: 'float' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud) python-3.x ×2