python入门第一天——控制流
来源:互联网 发布:重庆专业u盘数据恢复 编辑:程序博客网 时间:2024/06/10 12:54
# # -*-coding:utf-8-*-##if else 的使用# a = int(raw_input("enter first number a ="))# b = int(raw_input("enter second number b ="))# c = int(raw_input("enter the third number c="))# #get the higer number raw_input()函数用于接收从键盘输入的字符# if a>b:# if a>c:# print 'the biggest number is a=',a# else:# print 'the biggest number is c=',c# else:# if b>c:# print 'the biggest number is b=',b# else:# print 'the biggest number is c=',c# ##python中的if else 嵌套与C/java不同,使用elif代替 else if# number = 21# Running = True# while Running:# guess = int(raw_input("enter your number "))## if number == guess:# print 'congratulation you are right'# elif guess > number:# print 'sorry ,the number is bigger than real'# else:# print 'sorry ,the number is smaller than real'# ##while的使用方法# for i in range(1,5,2):# print 'this is ' , i , 'step'# if i == 5:# break# else:# print 'the for loop is over'##range的使用方式 range(low,high,step) low<=number<high##即number小于high,无法取值到high##for number in range (low,high,step)## number 为for循环中的变量,range中参数为范围##使用的是由内建的range函数生成的数的列表##break的使用方法:跳出离break最近的循环# while True:# input_str = raw_input('enter word or number')# if input_str == 'quit':# print 'the length of the string is', len(input_str)# break# else:# print 'the length of the string is',len(input_str)##continue 的使用方法:continue语句被用来告诉python跳过当前##循环块中的剩余语句,然后继续进行下一轮的循环# while True :# input_str = raw_input('input a word or number')# if input_str == 'quit' :# print 'Length of the word is ',len(input_str)# break# if len(input_str) < 3:# continue# print 'Legth of the word is ',len(input_str)# print 'break the circle'##下面是测试结果:# input a word or numbertest the continue demo# Legth of the word is 22# input a word or numberab# input a word or numberasc# Legth of the word is 3# input a word or numberquit# Length of the word is 4# break the circle
阅读全文
0 0
- python入门第一天——控制流
- Python一天入门5:控制流
- python入门第一天学习
- MongoDB——第一天 基础入门
- Linux(入门)——第一天
- MongoDB——第一天 基础入门
- java基础第一天——入门
- MongoDB——第一天 基础入门
- ongoDB——第一天 基础入门
- pytho入门第一天——函数
- 三天入门Python---基本语法(第一天)
- Python入门学习第一天_2017.11.24
- python学习——第一天
- Python Learning——第一天
- 21天学通python——第一天
- 蓝牙控制第一天
- 学通MongoDB——第一天 基础入门
- 8天学通MongoDB——第一天 基础入门
- 算法分析与设计回溯法之n皇后问题
- 《数学之美》第三章 统计语言模型
- 052day(静态成员)
- 学习计划
- 使用RxJava的retryWhen操作符实现token过期自动刷新
- python入门第一天——控制流
- 复制状态机(State Machine Replication)
- 在Ubuntu 16.04配置VNC Server (灰屏问题解决)
- Monitor项目开发走过的路~子线程Toast全解析
- JavaScript--函数声明、函数表达式、匿名函数、立即执行函数
- 到底怎么做需求分析,技术调研,技术设计?
- C++ 数据结构-树状数组
- 互联网技术体验
- Add to List 657. Judge Route Circle