In [ ]:
import random
n = int(input('您想要的整数个数:'))
r = int(input('您想要的整数的范围:'))
m = int(input('m的值:'))
k = int(input('k的值:'))
j = 0
a = [0 for i in range(r)]
b = [0 for i in range(r)]
for i in range(n):
a[i] = random.randint(1,r)
if (a[i] >= m) and (a[i] <=k):
b[j] = a[i]
j += 1
print('他们分别是:')
for i in range(n-2):
print(a[i],',',end='')
print(a[n-1])
print('范围在m到k之间的数有:')
for i in range(j-2):
print(b[i],',',end='')
print(b[j-1])
import math, random, msvcrt
def main():
n = int(input('n:'))
m = int(input('m:'))
k = int(input('k:'))
for i in range(n):
a[i] = random.randint(m, k)
print(a[i])
#while True:
# if ord(msvcrt.getch()) in [0,100]:
# break
print(math.log(a[i], 2))
if (math.log(a[i], 2) ==0.0):
print(0.0)
else:
print(1/(math.log(a[i], 2)))
#while True:
# if ord(msvcrt.getch()) in [0,100]:
# break
print('-------------------------------')
a = [0 for i in range(100000)]
main()
import random, math, subprocess
def win():
print('win')
def lost():
print('lost')
def game_over():
print('game over')
def show_team():
print('show_team')
def show_instruction():
print('show_instruction')
def menu():
print('''=====游戏菜单=====
1. 游戏说明
2. 开始游戏
3. 退出游戏
4. 制作团队
=====游戏菜单=====''')
def guess_game():
global i
global j
n = int(input('请输入一个大于0的整数,作为电脑猜数的上界,回车结束。'))
guess_times = 0
number = int(input('输入这个数'))
global s
i = 1
j = n
s = ''
max_times = math.ceil(math.log(n, 2))
while guess_times <= max_times:
if (s == '大'):
j = guess
elif (s =='小'):
i = guess
guess = random.randint(i, j)
guess_times += 1
print('一共可以猜', max_times, '次')
print('电脑已经猜了', guess_times, '次')
print('电脑猜的数为',guess)
s = input('电脑猜的是大还是小了')
if judge == '刚好':
win()
print('神秘数字是:', guess)
print('你比标准次数少', max_times-guess_times, '次')
break
elif s == '大':
print('抱歉,电脑猜大了')
else:
print('抱歉,电脑猜小了')
else:
print('神秘数字是:', number)
lose()
def main():
while True:
menu()
choice = int(input('请输入你的选择'))
if choice == 1:
show_instruction()
if choice == 2:
guess_game()
elif choice == 3:
game_over()
break
else:
show_team()
main()