zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    基于MFC的Media Player播放器的制作(1---播放器界面的布局)
    Codeforces 1182
    Codeforces 1169
    Codeforces 1167
    Codeforces 1166
    Codeforces 1148
    *Codeforces 1162
    Codeforces 1159
    点分治
    高斯消元*
  • 原文地址:https://www.cnblogs.com/zzuyczhang/p/12871359.html
Copyright © 2011-2022 走看看