|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- while 'C':
- print('我爱鱼C') #while循环,当循环执行的是true,当为flase时,停止执行
复制代码- i = 10
- while i: #现在给while循环指定了循环次数 i,每循环一次'xxxx'时,i就会减少一次,直到i = 0,结束循环
- print('xxxxx') # 布尔类型,在布尔类型中,true可以看做是1,flase可以看做是0,当i = 0时,循环flase,循环结束
- i = i - 1
复制代码- (10 < cost) and (cost < 20)
复制代码
关于短路逻辑与或者说是惰性求值,这里引用下甲鱼的例子
- not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9
- (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 时,再判断右边;
- 0 or 0 or 4 or 6 or 9
- 4
复制代码
动动手
- import random
- time = 3
- secret = random.randint(1,10) #这里导入了random 模块;自己也不是太了解,关于随机函数吧;times = 3,定义了三次机会;
- print('------我们来玩游戏吧------') # 这里的 . randint()这里是定义随机的范围
- temp = input("猜一猜我现在想的数字")
- guess = int(temp)
- while guess != secret:
- temp = input("哎呀,猜错了庆重新输入吧")
- guess = int(temp)
- if guess == secret:
- print("卧槽,你是我肚子里面的蛔虫吗")
- print("哼!猜中了也没有奖励")
- else:
- if guess > secret:
- print("哥,大了,大了")
- else:
- print("嘿,小了!")
- print("游戏结束")
复制代码
- temp = input('请输入一个数字')
- number = int(temp) #这段代码双重定义,i = 数字 ; j= i; j = *
- while number:
- i = number - 1
- while i:
- print('',end = '')
- i = i -1
- j = number
- while j:
- print('*',end = '')
- j = j - 1
- print()
- number = number - 1
-
复制代码 |
|