#!/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()