标签:style blog http color io os 使用 for div
2-1
print来显示变量的内容,仅用变量名时,输出的字符串使用单引号括起来的,这是为了让非字符串对象也能以字符串的方式显示在屏幕上,print语句使用str()函数显示对象,交互解释器调用repr()函数来显示对象
#!/usr/etc/env python string =raw_input("please type the string:\n") print string
#!/usr/etc/env python string =input("please type the string:\n") print string print type(string)
#!/usr/etc/env python i=0 while i<=10: print i i+=1
#!/usr/etc/env python for counter in range(11): print counter
#!/usr/etc/env python value=input("please type the value:\n") if value>0: print "This number is positive" elif value<0: print "This number is negative" else: print "This number is zero"
#!/usr/etc/env python #-*- coding:utf-8 -*- string =raw_input("please type the string:\n") print "for循环完成逐字符显示字符串" for i in string: print i print "while循环完成逐字符显示字符串" j=0 while j<len(string): print string[j] j+=1
#!/usr/etc/env python #-*- coding:utf-8 -*- aList =[1,2,3,4,5] j=0 print "for循环实现输出列表的和" for i in aList: print i j+=i print j print "while 循环实现输出列表的和" j=0 i=0 while i<len(aList): j+=aList[i] print aList[i] i+=1 print j
#!/usr/etc/env python #-*- coding:utf-8 -*- aList =(1,3,3) j=0 print "for循环实现输出列表的和" for i in aList: print i j+=i counter =float(len(aList)) print "平均值为:",j/counter print "while 循环实现输出列表的和" j=0 i=0 while i<len(aList): j+=aList[i] print aList[i] i+=1 print j print "平均值为:",j/counter
#!/usr/etc/env python #-*- coding:utf-8 -*- while True: i =input("please type the number:\n") if(0<i<100): print"success!" break else: pass
#!/usr/etc/env python #-*- coding:utf-8 -*- myList =[] i=0 sum=0 while i<5: counter=input("please enter the number:\n") myList+=[counter] i+=1 while True: print""" (1)取五个数的和 (2)取五个数的平均值 (3)退出 """ choose=input("please enter your choose:\n") if choose==1: for j in range(len(myList)): sum+=myList[j] print sum elif choose==2: for j in range(len(myList)): sum+=myList[j] print sum/(len(myList)+1) elif choose==3: break
print (-2*4)+(3**2)
#!/usr/etc/env python #-*-coding:utf-8-*- number1 =input("请输入第一个数值!:\n") number2 =input("请输入第二个数值!:\n") number3 =input("请输入第三个数值!:\n") if number1>number2: number2,number1=number1,number2 if number1>number3: number3,number1=number1,number3 if number2>number3: number3,number2=number2,number3 print number1,number2,number3 number1,number2,number3=number3,number2,number1 print number1,number2,number3
标签:style blog http color io os 使用 for div
原文地址:http://www.cnblogs.com/Fly9527/p/3989780.html