1、猜数字游戏
由某人随机出一个指定范围内的数,然后其他人一个一个猜,猜的过程中区间不断缩小,直到猜中为止。
import random
i = int(input("random start:"))
j = int(input("random end:"))
rand = random.randrange(i,j) # 生成区间内的随机数
print('Random number in [' + str(i) + ',' + str(j) + '] generated!')
num = int(input("Please guess the number:"))
count = 0
while(num != rand):
count += 1
if (num < rand):
print('Lower than the answer')
else:
print('Higher than the answer')
num = int(input('Guess the number again:'))
print(' You get the answer with [%d] times' % count)
2、有四个数字1、2、3、4,能组成多少个互不相同且数字不重复的三位数。
count = 1
lst = []
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if (i != k) and (i !=