求python大神帮我做下面几道题

1个回答

  • def Q_2(): n = input("Enter n:") term = input("Enter number of terms to sum: ") s = 0 for i in range(term): s += n/(2.0*i+1) print s def Q_3(): name = input("Enter a file name:") f = open(name,'r') lines = 0 char = 0 words = 0 for line in f: line = line.strip().split() lines += 1 for word in line: words += 1 chars +=len(word) f.close() print lines print words print chars def Q_4(): n = input("Enter length in inch: ") print n,"inches = ",n * 2.54,"cm" def Q_7(): name = input("Enter a file name:") f = open(name,'r') w = open("anotherFile.txt",'w') for line in f: line = line.strip().split() name = line[0][:-1] score = int(line[1]) if score >= 90: g = "A" elif score >=80: g = "B" elif score >=70: g = "C" elif score >=60: g = "D" else: g = "F" w.write(name+":",g) w.write("n") f.close() w.close() 写了半天,多给点分吧