---
# System prepended metadata

title: 0320 python 利用判斷式做終極密碼
tags: [practices]

---

###### tags: `practices`
# 0320 python 利用判斷式做終極密碼 
#利用判斷式 if elif else 及 while ture 猜數字
import random
a=100
b=0
i=1
ans=random.randint(1,100)
while  True :
  
    num=int(input('第{}輪終極密碼!plz Enter Number(0~100):'.format(i)))
    i+=1
    
    if num not in range(b,a+1):
        print(f'請輸入範圍{b}~{a}')
    
    elif num==ans:
        print('答對了!')
        break 
    elif num>ans:
        a=num         
        print('{}~{}'.format(b,num))
    else:
        b=num
        print('{}~{}'.format(num,a))