今天是我学习python的第一天,感觉不错,我一口气看了python简明教程的1到8章,哈哈,主要是因为前面的东西都是自己知道的,所以看得非常的快,呵呵呵,当然,我在看得时候还是写了几行代码,写了这么几行代码,我觉得python真的是一种很爽的东西,哈哈哈哈,好简洁啊,而且还不用受限于平台,也就是说,只要我们的代码中没有用到依赖于平台的东西的话,那么就可以把程序一个字都不改的放在不同的操作系统中使用,例如linux或者windows,更或者mac os,再在或者unix………………等等等等,和java一样的爽,虽然我觉得我可能学习java更有前途,但是不知道为什么,我一接触到python的时候,我发觉我的兴趣远远的超过了java:)
下面我把我今天联系的代码贴出来,呵呵,大家不要笑噢:)还有一点,我发现python好像不能用中文的注释,那样会出错
---------------------------------------------------------------------------
#!c:/python
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False # this causes the while loop to stop
elif guess < number:
print 'No, it is a little higher than that'
else:
print 'No, it is a little lower than that'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'
---------------------------------------------------------------------------
#!c:/python
#print the function's document string of printMax
def printMax(x, y):
''Prints the maximum of two numbers.
The two values must be integers.''
x = int(x) # convert to integers, if possible
y = int(y)
if x > y:
print x, 'is maximum'
else:
print y, 'is maximum'
printMax(3, 5)
print printMax.__doc__
---------------------------------------------------------------------------
#!c:/python
def CallCustomFunction(a,b):
print "the a=" + str(a) + ",the b=" + str(b)
print "this is CustomFunction"
strUserEnter = raw_input("Please enter a string:" )
print "user type is :" + strUserEnter
a = a + 1
b = b + 1
a = 1
b = 1
CallCustomFunction(a,b)
print "a=" + str(a) + ",b=" + str(b)
---------------------------------------------------------------------------
#!c:/python
for i in range(1,10):
print str(i) + "/t|"
else:
print "the for loop is over"
---------------------------------------------------------------------------
#!c:/python
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False # this causes the while loop to stop
elif guess < number:
print 'No, it is a little higher than that'
else:
print 'No, it is a little lower than that'
else:
print 'The while loop is over.'
# Do anything else you want to do here
print 'Done'
---------------------------------------------------------------------------
#!c:/python
#print the function's document string of printMax
def printMax(x, y):
''Prints the maximum of two numbers.
The two values must be integers.''
x = int(x) # convert to integers, if possible
y = int(y)
if x > y:
print x, 'is maximum'
else:
print y, 'is maximum'
printMax(3, 5)
print printMax.__doc__
---------------------------------------------------------------------------
#!c:/python
def CallCustomFunction(a,b):
print "the a=" + str(a) + ",the b=" + str(b)
print "this is CustomFunction"
strUserEnter = raw_input("Please enter a string:" )
print "user type is :" + strUserEnter
a = a + 1
b = b + 1
a = 1
b = 1
CallCustomFunction(a,b)
print "a=" + str(a) + ",b=" + str(b)
---------------------------------------------------------------------------
#!c:/python
for i in range(1,10):
print str(i) + "/t|"
else:
print "the for loop is over"