第二章

第四题
#!/usr/bin/env python
#for A
myString = raw_input('Please Input Any String To Test:')
print myString

#for B
myInt = raw_input('Please Input Any Integer To Test:')
Ints = int(myInt)
print Ints


第五题

#!/usr/bin/env python
# for a
Counts = 0
while Counts <= 10:
print Counts
Counts += 1
#for b
for i in range(11): # 0~10
print i


第六题

#!/usr/bin/env python
print "PLease Input Any To Test."
intToTest = raw_input('>>')
midInt = int(intToTest)
if midInt > 0:
print "+"
elif midInt < 0:
print "-"
elif midInt == 0:
print"Zero"

第七题

#!/usr/bin/env python
myString = raw_input('Please Input Any String To Test:')
for ch in myString:
print ch


第八题

#!/usr/bin/env python
maxIndex = 5
Aarray = [1,3,5,7,10]
sumA = 0
Counts = 0
while Counts < maxIndex:
sumA += Aarray[Counts]
Counts += 1
print 'Sum is %d' % sumA
#~~~~~~~~~~~~~~~~~~~
Barray = []
Counts = 0 #reStart
while Counts < maxIndex:
print 'Please Intput %dth Integer:' % (Counts+1),
Barray.append(int(raw_input()))
Counts += 1
sumB = 0
for i in Barray:
sumB += i
print 'Sum is %d' % sumB


第九题

#!/usr/bin/env python
avgArray = [1,3,5,7,10]
sums = 0
for i in avgArray:
sums += i
sums = float(sums)
print "The AVG is %.2f" % (sums/5.0)



第十题

#!/usr/bin/env python
on_off = True #switch
while on_off:
print "Please Input Any Integer"
try: # Test The 'ints' is on law or not
ints = int(raw_input('>>'))
except:
print "Error In IO,Please Try Again."
continue
if ints < 100 and ints > 0:
on_off = False
print "Done!"



第十一题

#!/usr/bin/env python
midArray = []
for i in range(5):
print "Please Enter %dth Integer:"%(i+1),
midArray.append(int(raw_input()))


while True:
sums = 0 #sum
for i in midArray:
sums += i
print "A:SUM B:AVG C:QUIT"
on_off = raw_input()
if on_off == 'A': # Just For Sum
print "Sum Is %d"%sums
elif on_off is "B": # For Avg
print "Avg Is %.2f"%(float(sums)/5)
else:
break
print"Done!"



第十六题

#!/usr/bin/env python
while True:
fileName = raw_input('Please Input File Name:')
try:
fobj = open(fileName,'r')
except:
print 'Eorre On File Name,Please Try Again.'
continue
break
for eachLine in fobj:
print eachLine,
fobj.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值