我正在尝试编写一个程序来发送UDP数据包,如 https://wiki.python.org/moin/UdpCommunication中的代码似乎是在Python 2中:
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Hello, World!"
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
Run Code Online (Sandbox Code Playgroud)
如果我在打印的东西周围加上括号,它只是将它打印在屏幕上.
我需要做些什么来完成这项工作?
所以,我从http://www.javascripter.net/math/primes/miller_rabin_pseudocode.txt读取了伪代码,并认为用 python 编写它会很酷。所以我写了这个:
n = input('Enter a number to test ')
n = int(n)
a=int(5)
d = n - 1
s = 0
while (d % 2 == 0):
s = s + 1
d = int(d/2)
x = a**d
x = x % n
if (x==1 or x==(n-1)):
print("probably prime")
r = int(1)
while(r<(s-1)):
x = x**2
x = x%n
if (x==1):
print ("composite")
if (x==(n-1)):
print ("probably prime")
print("if nothing above is printed n is composite") …Run Code Online (Sandbox Code Playgroud)