#!/usr/bin/env pythondef changeTime(H,M): timeH = H + float(M)/float(60) timeM = H*60 + M return [timeH,timeM]print changeTime(3,10)
第5题#!/usr/bin/env pythondef GD(G,pt = 0.1): return G*ptprint GD(100)print GD(100,0.3)
第6题#!/usr/bin/env pythondef printf(strings,*lists): LEN = len(strings) listKey = ['d','f','s'] nuEle = 0 nuEle = strings.count("%f") + strings.count("%d") + strings.count("%s")# for ch in strings:# if ch == "%" and strings.index(ch) != LEN-1: #The Code print strings.index(ch) aways show the index of firs"%"# nextCh = strings[strings.index(ch)+1] #I don,t know what happen...# if nextCh in listKey:# nuEle += 1 if nuEle != len(lists[0]): print "Wrong Element." return resultString = "" i = 0 iterStr = 0 while True: if strings[iterStr] == "%": try: nextChs = strings[iterStr+1] #Be sure not out of range except Exception: resultString += strings[iterStr] break nextChs = strings[iterStr+1] resultString += str(lists[0][i]) iterStr += 2 i += 1 else: resultString += strings[iterStr] iterStr += 1 if iterStr == LEN: break print resultStringprintf("abc