# coding: utf-8
                import random
                import os 
                
                os.system('clear')
                print('\n   数あて(1--99) \n')
                print('===============================\n')
                
                x = random.randint(1,99)
                count = 1
                y = int(input('数字入れて: ')) 
                
                while y > 0 and y < 100:
                    if y == x: 
                        rate = 1.0 / count
                        ans = ("You WIN! {}回であたった。勝率は{:.2f}。\n")
                        print(ans.format(count, rate))
                        break
                    elif y < x:
                        print('You are smaller than me!\n') 
                        count += 1
                    else:
                        print('You are larger than me!\n')
                        count += 1
                    y = int(input('数字入れて: '))
                if y < 0 or y > 100:
                      raise Exception("\n入力ミス. 1--99の数字を入れること.\n")
            
実行結果