#!/usr/bin/env pythonimport stringar = []Count = 0switches = Truewhile switches: print "Please Input %dth Digit:"%(Count+1), chs = raw_input() for ch in chs: #test the inputs is all digit or not if ch not in string.digits: switches = False break if switches == False: continue ar.append(int(chs)) Count += 1print arar.sort()print arar[-1::-1] = arprint ar
第4题#!/usr/bin/env pythonexamList = []Count = 0while Count != 5: print "Please Input %dth Result Of Exam:"%(Count+1), chs = raw_input() examList.append(float(chs)) Count += 1avgExam = float(sum(examList)) / 5print"Result Is %.2f "%avgExamif avgExam <= 100 and avgExam >= 90: print "A"elif avgExam < 90 and avgExam >= 80: print "B"elif avgExam < 80 and avgExam >= 70: print "C"elif avgExam < 70 and avgExam >= 60: print "D"elif avgExam < 60: print "E"
第5题#!/usr/bin/env pythonprint"Please Input Any Word To Test:",testWord = raw_input()for ch in testWord: print"%s"%ch,printfor ch in testWord[-1::-1]: print"%s"%ch,
#!/usr/bin/env pythonprint "Please Input First Word:",word_1 = raw_input()print "Please Input Second Word:",word_2 = raw_input()if len(word_1) != len(word_2): print"!=" exit()Count = 0for ch in word_1: if ch != word_2[Count]: print"!=" exit() Count += 1print "=="
#!/usr/bin/env pythonprint "Please Input Any Word To Test:"testWord = raw_input()Count = len(testWord) - 1for ch in testWord: if ch == testWord[Count]: Count -= 1 else: breakif Count == -1: print "=="else: print "!=" #!/usr/bin/env pythonprint "PLease Input Any Word To Test:",testWord = raw_input()rTestWord = ""for ch in testWord[-1::-1]: rTestWord += chtestWord += rTestWordprint testWord第6题 #!/usr/bin/env pythondef myStrip(strs): newString = "" Lens = len(strs) if strs[0] == " " and strs[-1] == " ": for ch in strs[1:Lens-1]: newString += ch return newString if strs[0] == " ": for ch in strs[1::]: newString += ch return newString if strs[-1] == " ": for ch in strs[:Lens-1:]: newString += ch return newString return strsprint "PLease Input Any Word To Test:",testWord = raw_input()print testWordprint "~~~~~~%s~~~~~"%(myStrip(testWord))第7题#!/usr/bin/env pythonnum_str = raw_input("Enter a number:")num_num = int(num_str)fac_list = range(1,num_num+1)print fac_listi = 0Count = 0allNu = len(fac_list)while i < allNu: if num_num