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

原创粉丝点击