阅读 51

Python 猜数小程序(练习)

------Game1
def guess(armnums):
    number = random.randint(1, 9) 
    chances = 0  
    while chances < 5: 
        print("System guess :%d"%number)
        if armnums == number:  
            print("System   Get it !!!")
            break
        elif armnums < number: 
            print("System guess was too high  !") 
            number=random.randint(1, number) 
        else:  
            print("System guess was too low !") 
            number=random.randint(number, 9) 
        chances += 1 
    if not chances < 5: 
        print("System LOSE  YOU WIN !!!")
 
if __name__ == __main__: 
    sysflag=True 
    while sysflag:
        arm=input("Please input a arm number (between 1 and 9):")
        guess(int(arm))
        flag=input("Continue Y/N ?:")        
        if flag.upper()==N:
            print(Game over!)
            sysflag=False

------Game2
import random 
  

def guess(armnums):
    number = random.randint(1, 9) 
    chances = 0  
    while chances < 5: 
        print("System guess :%d"%number)
        if armnums == number:  
            print("System   Get it !!!")
            break
        elif armnums < number: 
            print("System guess was too high  !") 
            number=random.randint(armnums, number) 
        else:  
            print("System guess was too low !") 
            number=random.randint(number, armnums) 
        chances += 1   
 
if __name__ == __main__: 
    sysflag=True 
    while sysflag:
        arm=input("Please input a arm number (between 1 and 9):")
        guess(int(arm))
        flag=input("Continue Y/N ?:")        
        if flag.upper()==N:
            print(Game over!)
            sysflag=False


------Game3
import random 
  
def guess(armnums):
    list =[]
    number = random.randint(1, 1000)  
    fmax = 1000
    fmin = 1
    while True: 
        print("System guess :%d"%number)
        if armnums == number:  
            print("System   Get it !!!")
            break
        elif armnums < number: 
            print("System guess was too high  !") 
            fmax=number 
        else:  
            fmin=number
            print("System guess was too low !") 
        list.append(number) 
        number=random.randint(fmin,fmax) 
        if number in list:
            number=random.randint(fmin,fmax) 
 
if __name__ == __main__: 
    sysflag=True 
    while sysflag:
        arm=input("Please input a arm number (between 1 and 1000):")
        guess(int(arm))
        flag=input("Continue Y/N ?:")        
        if flag.upper()==N:
            print(Game over!)
            sysflag=False

 

原文:https://www.cnblogs.com/zzuyczhang/p/12871359.html

文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐