简介:利用随机函数生成0~999中的随机整数。当输入的数大于或者小于这个数,给出相应提示,猜对则结束!
import random cmp = random.randint(0,999) time = 1 small = 0 big = 999 answer = int(input("Input your answer(%d-%d): " %(small, big))) while answer != cmp: time += 1 if answer > cmp: print("Your answer is big") if answer > big: big = big else: big = answer answer = int(input("Input your answer(%d-%d): " %(small, big))) else: print("Your answer is small") if answer < small: small = small else: small = answer answer = int(input("Input your answer(%d-%d): " %(small, big))) print("The answer is %d. You get it by %d times" %(cmp, time))
讯享网
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/119022.html