【PPD08】类
GuessNum.py
- 请修改提示信息,print() 里的内容
class SecretNumber:
"""猜测目标数字"""
def __init__(self,target):
self.target=target
def check(self,guess):
if self.target<guess:
return 1
elif self.target>guess:
return -1
elif self.target==guess:
return 0
secret=SecretNumber(100) # new对象,目标数字为100
# 可以用randint随机数 ,把上面一行删除
# from random import randint 放在最上方
# secret=SecretNumber(randint(1,100))
while True:
guess=int(input("?"))
result=secret.check(guess)
if result==-1:
print("太小了")
if result==1:
print("太大了")
if result==0:
print("猜对了,Bingo")