sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print sock.recv(8192) qcount = 1 while qcount <= 20: qcount+=1 qnumber=sock.recv(8192) print qnumber question=sock.recv(8192) # print question qrtxt = readqr(question) print(qrtxt) answer = word2num(qrtxt) answerwords = num2words(answer) print answerwords answerqr = pyqrcode.create(answerwords) answertext = answerqr.text(quiet_zone=1) # print answertext sock.send(answertext) reply = sock.recv(1024).strip() if reply == "Correct": continue else: print reply print sock.recv(8192) sock.close()
question,answer = genquestion() ##generate my own QR code data questionqr = pyqrcode.create(question) questiontext = questionqr.text(quiet_zone=1) conn.send("%s\n\n"%questiontext) print "Question: %s"%question print "Answer: %s"%answer data=conn.recv(8192) data = data.strip() playerwords = readqr(data) if playerwords: try: print "PlayerAnswer: %s"%playerwords playeranswer = word2num(playerwords) print "PlayerAnswer: %s"%playeranswer except: playeranswer = False if playeranswer == answer: conn.send("Correct\n") else: conn.send("Incorrect Answer\nSession Terminated\n") conn.close() sys.stdout.flush() break else: conn.send("Could not Parse QR code\nSession Terminated\n") conn.close() sys.stdout.flush()
question, answer = genquestion() ##generate my own QR code data questionqr = pyqrcode.create(question) questiontext = questionqr.text(quiet_zone=1) conn.send("%s\n\n" % questiontext) print "Question: %s" % question print "Answer: %s" % answer data = conn.recv(8192) data = data.strip() playerwords = readqr(data) if playerwords: try: print "PlayerAnswer: %s" % playerwords playeranswer = word2num(playerwords) print "PlayerAnswer: %s" % playeranswer except: playeranswer = False if playeranswer == answer: conn.send("Correct\n") else: conn.send("Incorrect Answer\nSession Terminated\n") conn.close() sys.stdout.flush() break else: conn.send("Could not Parse QR code\nSession Terminated\n") conn.close() sys.stdout.flush()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) print sock.recv(8192) qcount = 1 while qcount <= 20: qcount += 1 qnumber = sock.recv(8192) print qnumber question = sock.recv(8192) # print question qrtxt = readqr(question) print (qrtxt) answer = word2num(qrtxt) answerwords = num2words(answer) print answerwords answerqr = pyqrcode.create(answerwords) answertext = answerqr.text(quiet_zone=1) # print answertext sock.send(answertext) reply = sock.recv(1024).strip() if reply == "Correct": continue else: print reply print sock.recv(8192) sock.close()