鱼C论坛

 找回密码
 立即注册
查看: 1079|回复: 5

第四课 不太懂 求指教

[复制链接]
发表于 2018-6-9 14:26:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import random as r

  2. secret = r.randint(1,10)

  3. print('不妨猜一下小甲鱼现在心里想的是哪个数字:', end = ' ')

  4. times = 3

  5. [color=Red]while times:
  6.     temp = input() #不太理解
  7.     guess = int(temp )#不太理解
  8.     times -= 1[/color]
  9.    
  10.     if guess == secret:
  11.         print('哎呀,你是小甲鱼肚里的蛔虫吗?')
  12.         print('哼~猜中了也没有奖励!')
  13.         break                                                           #猜中后跳出循环,break是后续“分支与循环”中的内容
  14.     else:
  15.         if guess > secret:
  16.             print('哥,大了大了~~~')
  17.         else:
  18.             print('嘿,小了小了~~~')
  19.    
  20.        [color=Red] if times:
  21.             print('你还有%d次机会,请重新输入:' % times, end = ' ') #不理解  if times 是有次数的话 打印剩余机会 反之 打印已用完 结束游戏  '你还有%d次机会,请重新输入:' % times, end = 这句不太理解[/color]
  22.         else:
  23.             print('机会用光咯,非常遗憾!')

  24. print('游戏结束,不玩啦^_^')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-6-9 16:09:04 | 显示全部楼层
hi 请lz参考

  1. import random as r

  2. secret = r.randint(1,10)

  3. print('不妨猜一下小甲鱼现在心里想的是哪个数字:', end = ' ')

  4. times = 3

  5. [color=Red]while times:
  6.     temp = input() #不太理解   |     此处接收用户的输入
  7.     guess = int(temp )#不太理解    |    因为通过input()函数输入的均是字符型,因此需要通过 int()函数转换为整型
  8.     times -= 1[/color]
  9.    
  10.     if guess == secret:
  11.         print('哎呀,你是小甲鱼肚里的蛔虫吗?')
  12.         print('哼~猜中了也没有奖励!')
  13.         break                                                           #猜中后跳出循环,break是后续“分支与循环”中的内容
  14.     else:
  15.         if guess > secret:
  16.             print('哥,大了大了~~~')
  17.         else:
  18.             print('嘿,小了小了~~~')
  19.    
  20.        [color=Red] if times:
  21.             print('你还有%d次机会,请重新输入:' % times, end = ' ') #不理解  if times 是有次数的话 打印剩余机会 反之 打印已用完 结束游戏  '你还有%d次机会,请重新输入:' % times, end = 这句不太理解[/color]      |     打印剩余机会并提示用户重新输入;print()函数默认以换行结尾,end=''  表示已''结尾、即:不换行
  22.         else:
  23.             print('机会用光咯,非常遗憾!')

  24. print('游戏结束,不玩啦^_^')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-9 16:25:24 | 显示全部楼层

while times:
    temp = input() #不太理解   |     
    guess = int(temp )#不太理解   
    times -= 1
这几句具体是什么意思呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-9 16:26:05 | 显示全部楼层
xn360906 发表于 2018-6-9 16:25
while times:
    temp = input() #不太理解   |     
    guess = int(temp )#不太理解   

end=''  是什么意思呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-9 16:35:54 | 显示全部楼层
xn360906 发表于 2018-6-9 16:26
end=''  是什么意思呢

举个栗子

  1. >>> for each in range(5):
  2.         print(each)

  3.        
  4. 0
  5. 1
  6. 2
  7. 3
  8. 4
  9. >>> for each in range(5):
  10.         print(each , end='')

  11.        
  12. 01234
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-9 21:03:00 | 显示全部楼层
xn360906 发表于 2018-6-9 16:26
end=''  是什么意思呢

print()括号里是打印出来的字符,比如print("1")就打印出1;end出现在print内代表的意思是print里面打印出的字符末尾以什么结尾,比如你要在屏幕上输出1,并且以“群小姐姐”结尾,那么就应该这么写print语句:
print("1",end="群小姐姐")
如有错误,还请鱼油们指教。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-30 18:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表