在业余时间学习一下跨平台代码python。
下面是http://courses.ischool.berkeley.edu/i155/su13/schedule.htm下的例题代码。留作未来参考语法。
1 #hw1_1.py 2 x=input("Input the number of gallons of gasoline:") 3 print "Equivalent number of liters:",x*3.7854 4 print "Number of barrels of oil required to produce it:",x/19.5 5 print "Price in US dollars:$",x*3.56,
1 #hw1_2.py 2 import sys 3 name=raw_input("Enter your name:") 4 n=len(name) 5 print name[n-1].upper(), 6 #No space between the output letter 7 sys.stdout.softspace=0 8 i=n-2 9 while i>=0: 10 print name[i].lower(), 11 sys.stdout.softspace=0 12 i=i-1 13
1 #hw1_3.py 2 n=input("Enter a size:") 3 for j in range(0,n): 4 for i in range(-n+1,n): 5 if abs(i)<=j : 6 print j-abs(i)+1, 7 else: 8 print ' ', 9 print ""
#hw1_4.py n=input("Enter a size:") for i in range(0,n): for j in range(0,n): if (i+j)%2==0: print "X", else: print " ", print ""