num = raw_input('input a num: ') if num > 0: print'正数', elif num < 0: print'负数', else: print'0',
2-7
1 2 3 4 5 6 7 8 9
myStr = raw_input('input a str: ') i = 0 while i < len(myStr): print myStr[i], i += 1
myStr = raw_input('input a str: ') for c in myStr: print c,
2-8
1 2 3 4 5 6 7 8 9 10 11 12
aList = list() for i inrange(5): num = raw_input('input a num : ') aList.append(int(num))
i = 0 myNum = 0 while i < len(aList): myNum += aList[i] i += 1
print'myNum is : %d' % (myNum)
2-9
1 2 3 4 5 6
aTuple = [ 1, 2, 3, 5, 6] myNum = 0 for i in aTuple: myNum += i
print'average value is : %f ' % (float(myNum) / len(aTuple))
2-10
1 2 3 4 5 6 7 8
b = bool(False) while b isFalse: num = int(raw_input('input a num among 1 to 100 : ')) if num >= 1and num <= 100: print'succeed!' break else: print'input error!'