分支和循环
在Python的分支和循环里面,缩进是极其重要的。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14score = input("请输入你的分数:") score = int(score) if 0<=score<60: print("you are the hunzi") elif 60<=score<80: print("小混子") elif 80<=score <90: print("Not Bad") elif score== 100: print("NNN") else: print("请输入0—100之间的数好吗哥")
复制代码
1
2
3
4
5
6
7
8
9>>> score =96 >>> level= ("D" if 0<=score<60 else "C" if 60<=score<80 else "B" if 80<=score<100 else "A" if score == 100 else "请输入0—100之间的分值") >>> print(level) B
复制代码
1
2
3
4
5
6
7
8
9
10age=18 isMale=True if age <18 print("我的心禁止访问") else: if isMale: print("you are the boss") else: print("Sorry,")
复制代码
1
2
3
4
5
6
7
8
9
10
11
12>>> love ="Yes" >>> while love =="Yes": love =input("今天你还爱我吗?n") 今天你还爱我吗? Yes 今天你还爱我吗? Yes 今天你还爱我吗? no//跳出循环
计算从1+到1000000的和
死循环
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16>>> while 1: answer=input("我可以退出循环了吗?n") if answer=="行": break else: print("好的 那我继续循环啦") 我可以退出循环了吗? 不行 好的 那我继续循环啦 我可以退出循环了吗? no 好的 那我继续循环啦 我可以退出循环了吗? 行
最后
以上就是喜悦嚓茶最近收集整理的关于Python日常Day5的全部内容,更多相关Python日常Day5内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复