工具:pycharm
2.4
print "input a string"
str1 = raw_input() #接收用户键盘输入
print str1
print "input a number"
str2 = int(raw_input()) #转化为int类型
print str2
2.5
i = 0
while i <= 10 :
print i,
i = i+1
print '\n'
for j in range(11) : #注意range为11
print j,
2.6
x = int(raw_input())
if x > 0 :
print "positive"
elif x < 0 :
print "negative"
else:
print "x = 0"
2.7
print "input a string"
x = raw_input()
for i in range(len(x)) :
print x[i],
print '\n'
j = 0
while j < len(x) : #此处应无等号
print x[j],
j = j+1
2.8
list = [9,8,7,6,5]
sum = 0
i = 0
while i < len(list) :
sum = sum + list[i]
i = i + 1
print sum
sum = 0
for j in range(len(list)) :
sum = sum + list[j]
print sum
#接收用户输入的5个数,存入list并求和
count = 0
yoursum = 0
while count < 5 :
print "input a number"
list[count] = int(raw_input())
yoursum = yoursum + list[count]
count = count + 1
print "your list is ",
print list
print "your sum is ",
print yoursum
2.9
from __future__ import division #floor除法
list = [1,8,1,6,10]
sum = 0
i = 0
while i < len(list) :
sum = sum + list[i]
i = i + 1
print sum
print sum/5
2.10
i = True
while i == True :
print "input a number between 0-100"
x = int(raw_input())
if 0<x<100 :
print "ok"
i = False
else:
print "not suit"
2.11
from __future__ import division
def sum() :
list = []
count = 0
yoursum = 0
while count < 5 :
print "input a number"
list.append(int(raw_input()))
yoursum = yoursum + list[count]
count = count + 1
print "your list is ",
print list
print "your sum is ",
print yoursum
def ave() :
list = []
count = 0
yoursum = 0
while count < 5 :
print "input a number"
list.append(int(raw_input()))
yoursum = yoursum + list[count]
count = count + 1
print "your list is ",
print list
print "your ave is ",
print yoursum/5
i = True
while i == True :
print "1.sum 5 number"
print "2.average 5 number"
print "x.quit"
print '----------------------------'
print "input order"
order = raw_input()
if order == 'x' :
print "over"
i = False
elif int(order) == 1 :
sum()
elif int(order) == 2 :
ave()
else:
print "not an order"
2.15
print "input three number"
x = int(raw_input())
a = int(raw_input())
b = int(raw_input())
if a<b<x :
print a,b,x
elif a<x<b :
print a,x,b
elif b<a<x :
print b,a,x
elif b<x<a :
print b,x,a
elif x<b<a :
print x,b,a
else:
print x,a,b