Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

(Python) - Typing out sum in answer area

I've been trying to code a system to solve one of those "Are you a bot" type of captchas in a game.

Pretty much what it does is gives you a mathematical question from 1-200 numbers (ex 19 + 163) and asks you to solve it at random times throughout the gameplay.

with Pyautogui I managed to find the numbers accordingly on the screen (scanning the region for the number 1-9, then adding it to the according variable (i made 5 variables from number1 to number5)

Using the example above (19 + 163) it would correspond with

19

number1 = 1, number2 = 9

163

number3 = 1, number4 = 6 and number5 = 3

and then i made a simple calculating system which is :

sum1 = ((number1 * 10) + number2)
sum2 = ((number3 * 100) + (number4 * 10) + number5)
sum = sum1 + sum2
print(sum)

But is there a way to make it so that the sum will display it in 3 seperate numbers instead of showing let's say (sum = 193) it would show (sum = 1, 9, 3) and then type it out in the answer area (I had an idea of using import keyboard for typing the answer out but i'm not sure if it works in this case)

or even better in this case if there is a way to take the sum and then make it type it out in the answer area by the code?

https://imgur.com/a/XYXrgeX (Picture of the Bot captcha)

question from:https://stackoverflow.com/questions/65540902/python-typing-out-sum-in-answer-area

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

sum1 = ((number1 * 10) + number2)
sum2 = ((number3 * 100) + (number4 * 10) + number5)
sum_ = sum1 + sum2

lst = list(str(sum_))
sum_ = ""

for i in lst:
  sum_ = sum_ + str(i) + ", "

print(sum_[:-2])

This basically turns the sum into a list of digits and then combines then all while adding commas in between.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...