#2
ysr28572023-03-18 23:16
|
如下是用VB6.0编程的快速判断素数的可调用程序:
Private Function fenjieyinzi(sa As String) As String
Dim x, a, b
x = sa
b = Int(Sqr(Val(x)) / 2)
If x = 3 Or x = 2 Then
a = True
Else
If x Mod 2 = 0 Then
a = False
Else
For I = 3 To 2 * b + 1 Step 2
If x Mod I = 0 Then
a = False
Exit For
Else: a = True
End If
Next
End If
End If
If a = True Then
fenjieyinzi = "这是个素数"
Else
fenjieyinzi = "2*2"
End If
如何转化成python版的可调用程序或叫可调用函数?