鱼C论坛

 找回密码
 立即注册
查看: 2174|回复: 0

[学习笔记] 第四节课课后笔记

[复制链接]
发表于 2019-11-30 10:40:39 | 显示全部楼层 |阅读模式

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

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

x
  1. while 'C':
  2.          print('我爱鱼C') #while循环,当循环执行的是true,当为flase时,停止执行
复制代码
  1. i = 10
  2. while i: #现在给while循环指定了循环次数 i,每循环一次'xxxx'时,i就会减少一次,直到i = 0,结束循环
  3.       print('xxxxx') # 布尔类型,在布尔类型中,true可以看做是1,flase可以看做是0,当i = 0时,循环flase,循环结束
  4.       i = i - 1
复制代码
  1. (10 < cost) and (cost < 20)
复制代码

关于短路逻辑与或者说是惰性求值,这里引用下甲鱼的例子
  1. not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9  
  2. (not 1) or (0 and 1) or (3 and 4) or (5 and 6) or (7 and 8 and 9) #not > and >or ;and 为true时取值是最右边的;or 执行时,左边为true时,取左边,左边位flaes 时,再判断右边;
  3. 0 or 0 or 4 or 6 or 9
  4. 4
复制代码


动动手
  1. import random
  2. time = 3
  3. secret = random.randint(1,10) #这里导入了random 模块;自己也不是太了解,关于随机函数吧;times = 3,定义了三次机会;
  4. print('------我们来玩游戏吧------') # 这里的 . randint()这里是定义随机的范围
  5. temp = input("猜一猜我现在想的数字")
  6. guess = int(temp)
  7. while guess != secret:
  8.     temp = input("哎呀,猜错了庆重新输入吧")
  9.     guess = int(temp)
  10.     if guess == secret:
  11.             print("卧槽,你是我肚子里面的蛔虫吗")
  12.             print("哼!猜中了也没有奖励")
  13.     else:
  14.             if guess > secret:
  15.                     print("哥,大了,大了")
  16.             else:
  17.                     print("嘿,小了!")
  18. print("游戏结束")
复制代码


  1. temp = input('请输入一个数字')
  2. number = int(temp) #这段代码双重定义,i = 数字 ; j= i; j = *
  3. while number:
  4.     i = number - 1
  5.     while i:
  6.         print('',end = '')
  7.         i = i -1
  8.     j = number
  9.     while j:
  10.         print('*',end = '')
  11.         j = j - 1
  12.     print()
  13.     number = number - 1
  14.         
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-14 01:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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