7-2 jmu-python-猜数游戏(10 point(s)) 【python】

7-2 jmu-python-猜数游戏(10 point(s))

用户从键盘输入两个整数,第一个数是要猜测的数n(<10),第二个数作为随机种子,随机生成一个1~10的整数,如果该数不等于n,则再次生成随机数,如此循环,直至猜中数n,显示“N times to got it”,其中N为猜测的次数。
输入格式:

直接输入两个整数,以空格间隔。其中第一个数为要猜测的数,第二个数是随机种子
输出格式:

N times to got it
输入样例:

4 10

输出样例:

7 times to got it

思路
照着题意写 就行了

但是只能用 PYTHON 才能A

AC代码

import random
n, m = map(int, input().split())
count = int(1)
random.seed( m )
num = int(random.randint(1, 10))
while True :
    if (num == n):
        break
    count = count + 1
    num = int(random.randint(1, 10))
print("{} times to got it".format(count))


原文地址:https://www.cnblogs.com/Dup4/p/9433180.html