Answer the question
In order to leave comments, you need to log in
How to create a bot in a telegram with a game of bulls and cows (there is a program)?
In general, I puzzled myself with the creation of a bot in a telegram with a game of bulls and cows (there are rules on Wikipedia). In short: the bot guesses a random four-digit number in which the numbers do not repeat. The user, in turn, must guess, after each attempt, finding out the number of matching digits and their positions (bulls) and simply the fact that there is a digit in the desired number (cows). I already wrote the prog itself in python, with it, fortunately, there are no problems. Everything rests on the fact that I need to adapt the finished program to the work of the bot, but this does not work out for me - the usual methods do not work. I am inexperienced and I think that these are the costs of working with
bots
import random
random_numbers_list=[]
amount_inlist=len(random_numbers_list)
while amount_inlist!=4537:
number=random.randint(1000,10000)
n1=number%10
n2=number//10%10
n3=number//100%10
n4=number//1000
if n1!=n2 and n1!=n3 and n1!=n4 and n2!=n3 and n2!=n4 and n3!=n4:
random_numbers_list.append(number)
amount_inlist=len(random_numbers_list)
def f(random_numbers_list):
n=[]
for i in random_numbers_list:
if i not in n:
n.append(i)
return n
random_numbers_list=f(random_numbers_list)
random_numbers_list.sort()
our_number=random.choice(random_numbers_list)
s1=our_number%10
s2=our_number//10%10
s3=our_number//100%10
s4=our_number//1000
secretspisok=[s4,s3,s2,s1]
bull=0
cow=0
print(our_number)
while bull<4:
cow=0
bull=0
attempt=int(input())
a1=attempt%10
a2=attempt//10%10
a3=attempt//100%10
a4=attempt//1000
attemptspisok=[a4,a3,a2,a1]
for a in range(0,4):
if secretspisok[a]==attemptspisok[a]:
bull+=1
for a in range(0,4):
for b in range (0,4):
if secretspisok[a]==attemptspisok[b]:
cow+=1
print('быков:',bull, 'коров:', int(cow)-int(bull))
if bull==4:
print('Вы победили!Ура!')
def choose_number(random_numbers_list):
random_numbers_list=[]
amount_inlist=len(random_numbers_list)
while amount_inlist!=4537:
number=random.randint(1000,10000)
n1=number%10
n2=number//10%10
n3=number//100%10
n4=number//1000
if n1!=n2 and n1!=n3 and n1!=n4 and n2!=n3 and n2!=n4 and n3!=n4:
random_numbers_list.append(number)
amount_inlist=len(random_numbers_list)
def f(random_numbers_list):
n=[]
for i in random_numbers_list:
if i not in n:
n.append(i)
return n
random_numbers_list=f(random_numbers_list)
return(random_numbers_list)
our_number=random.choice(choose_number)
our_number=random.choice(choose_number(random_numbers_list))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question