2010年(19)
分类:
2010-05-17 23:50:40
2-3、在python中取余与C中不同。在python中
>>> 9 % 4.0
1.0
而在C中取余操作只能对一个int型的进行取余。2 + “str”这样会报错,与C中一样。
2-5#!/usr/bin/env python
#Filename: test.py
i = 0
while (i <= 10):
print i
i += 1
对于for循环来说,range(N),取的数是0到N-1
#!/usr/bin/env python
#Filename: test.py
for i in range(11):
print i
2-11s = raw_input(),从键盘输入得到的是一个字符串,如果你输入5,相当于‘5’,如果你要把它当成数据的数,要把它进行转换:int(s)
#!/usr/bin/env python
#Filename: test.py
while True:
sum = 0
for i in range(5):
str = raw_input("please input num:")
sum += int(str)
while True:
print "Please select:"
print "(1)sum of five number"
print "(2)average of five number"
print "(x)quit"
s = raw_input()
if (s == 'x'):
exit()
elif (s == '1'):
print "the sum is %d" %(sum)
break
elif (s == '2'):
print "the average is %d" % (sum / 5.0)
break
else:
print "Error,Please select again!"