|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
times = 3
secret = random.randint(1,10)
print('----我要打十个----')
# 这里先给guess赋值(赋一个绝对不等于secret的值)
guess = 0
# print()默认是打印完字符串会自动添加一个换行符,end=" "参数告诉print()用空格代替换行
# 嗯,小甲鱼觉得富有创意的你应该会尝试用 end="JJ"?
temp = input("不妨猜猜阿伟想在想的是哪个数字:",end=" ")#end引号里有空格 <------------------- 看这里看这里 官方报错说没有input的关键词参数
while type(temp) != type(1):#这种想法是因为type(1)会返回<class 'int'>,如果type(temp)返回结果一只说明输入是整数
print("抱歉!格式不合法",end=" ")
temp = imput("请输入一个整数:",end=" ")
- #coding:gbk
- import random
- times , count = 3 , 0
- secret = random . randint(1,10)
- print('----我要打十个----')
- guess = 0
- while guess != secret and count < times :
- temp = input("不妨猜猜阿伟想在想的是哪个数字:")
- if not temp . isdigit():
- print("抱歉!格式不合法")
- else:
- guess = int(temp)
- if guess == secret:
- print('恭喜你,猜对了!')
- break
- else:
- if guess > secret:
- print('猜大了!')
- else:
- print('猜小了!')
- count += 1
- if count < times:
- print('再猜一次')
- else:
- print('很遗憾,' , times , '次机会用完了!')
- print('游戏结束。')
复制代码
|
|