guess numbers

guess numbers game

The computer will choose 4 numbers randomly and in a random order. You can input to guess the numbers and the order.

If your numbers/number are/is included but not the same order, you will get “o”; if your numbers/number are/is the same order as the original one, you will get “△”‘

Computer will record the times you guess.

If you want to stop and know the answer, please input “0000”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#instruction
print('The computer will choose 4 numbers randomly and in a random order. You can input to guess the numbers and the order.'
'If your numbers/number are/is included but not the same order, you will get "o"; if your numbers/number are/is the same order as the original one, you will get "△"'
'Computer will record the times you guess.'
'If you want to stop and know the answer, please input "0000"')


#create the number
import random
a=str(random.randint(0,9))

b=str(random.randint(0,9))
while a==b:
b=str(random.randint(0,9)) #if the numbers are the same, change the number

c=str(random.randint(0,9))
while a==c or b==c:
c=str(random.randint(0,9))

while True:
d=str(random.randint(0,9))
if a!=d and b!=d and c!=d:
break


#input the guessing number and start to record the times
number=list(input())
i=1

#check whether the numbers are in or have the same order
while True:
if number[0] == '0' and number[1] == '0' and number[2] == '0' and number[3] == '0':
break
if a == number[0] and b == number[1] and c == number[2] and d == number[3]:
break
triangle=0
circle=0 #if it is right, jump out of the loop
if a in number:
if a == number[0]:
triangle=triangle+1
else:
circle=circle+1
if b in number:
if b == number[1]:
triangle=triangle+1
else:
circle=circle+1
if c in number:
if c == number[2]:
triangle=triangle+1
else:
circle=circle+1
if d in number:
if d == number[3]:
triangle=triangle+1
else:
circle=circle+1
#show the result and allow the user to input again
print('△:',triangle,'o:',circle)
number=list(input())
i=i+1
#show the right one and the times used
if number[0] == '0' and number[1] == '0' and number[2] == '0' and number[3] == '0':
print('sorry, it is',a,b,c,d,', you used',i,'times.')
else:
print('you are right, it is',a,b,c,d,', you used',i,'times.')

example:

The computer will choose 4 numbers randomly and in a random order. You can input to guess the numbers and the order.If your numbers/number are/is included but not the same order, you will get “o”; if your numbers/number are/is the same order as the original one, you will get “△”Computer will record the times you guess.
1234
△: 0 o: 1
5678
△: 0 o: 3
6781
△: 0 o: 2
8762
△: 1 o: 2
2567
you are right, it is 2 5 6 7 , you used 5 times.