第一个python程序
下版本功能预计:
计算学年学习分=(第一学期+第二学期)/2
输入班级起始学号和末尾学号,输出学习分并排序
#! usr/bin/python #coding=utf-8 //
import xlrd
xlsfile=r'C:\Users\Chen\Desktop\1.xls'
book=xlrd.open_workbook(xlsfile)
#打开文件,获取book对象
sheet_name=book.sheet_names()[0]
print (sheet_name)
sheet1=book.sheet_by_name(sheet_name)
sheet0=book.sheet_by_index(0)
diyilie=sheet1.col_values(0)
xuehao=input('请输入学号:')
position=diyilie.index(str(xuehao))
information=sheet1.row_values(position)
print ('您要查询的学生为:', information[1])
print('在表格的第', position, '行')
number=int(input('请输入第一学期的课程数:'))
print (number)
count=0
score1=0
score2=0
while count<number:
information=sheet1.row_values(position)
print(information[2],
information[4], information[6], information[8])
information[6]=float(information[6])
information[8]=float(information[8])
count=count+1
score1=score1+information[6]*information[8]
score2=score2+information[8]
position=position+1
print ('第一学期学习分:', score1/score2*0.7)
kechengshu=diyilie.count(xuehao)
second=kechengshu-count
print('第二学期的课程数:', second)
score1=0
score2=0
count=0
while count<second:
information=sheet1.row_values(position)
print(information[2], information[4], information[6], information[8])
if 'P' in information[6]:
print('PASS不计入分数')
information[6]=0
information[8]=0
information[6]=float(information[6])
information[8]=float(information[8])
position=position+1
count=count+1
score1=score1+information[6]*information[8]
score2=score2+information[8]
print('第二学期学习分:', score1/score2*0.7)
运行界面:

浙公网安备 33010602011771号