导航:首页 > 编程语言 > stus在python

stus在python

发布时间:2022-08-08 11:41:11

⑴ 怎么往jsp里传递一个值 在取出来request.setAttribute("stus", stus);

stus.size() 得到是 0 ?

如果是0的话,你就成功了。
因为如果没成功,就该报错了
没成功的话 stus 就是 null,根本无法调用size方法

⑵ 如何在java中将一个数组转换为一个集合

java.util.Arrays

Student[] stus = new Student[10];

ArrayList list = new ArrayList();

list = listArrays.asList(stus);

这样就可以把数组stus转换为List了

⑶ 定义一个Student类,包括姓名、学号、成绩三个成员变量以及getName()、getNo()、getScore()三个方法。在构

//参考程序:

#include"iostream"

#include"string"

usingnamespacestd;

classStudent

{

private:

intno; //学号

stringname; //姓名

intscore; //成绩

public:

Student()

{}

Student(intno,stringname,intscore)

{

this->no=no;

this->name=name;

this->score=score;

}

stringgetName()

{

returnname;

}

intgetNo()

{

returnno;

}

intgetScore()

{

returnscore;

}

voiddisplay()

{

cout<<no<<" "<<name<<" "<<score<<endl;

}

};

voidsort(Studentstus[],intlen)

{

inti,j,k;

Studenttemp;

for(i=0;i<len-1;i++)

{

k=i;

for(j=i+1;j<len;j++)

if(stus[j].getScore()>stus[k].getScore())

k=j;

if(k!=i)

{

temp=stus[k];

stus[k]=stus[i];

stus[i]=temp;

}

}

}

voidmain()

{

inti;

intlen=5;

Studentstus[20];

intno;

stringname;

intscore;

cout<<"请输入20个学生的信息(学号、姓名、成绩):"<<endl;

for(i=0;i<len;i++)

{

cout<<"No."<<i+1<<":";

cin>>no>>name>>score;

stus[i]=Student(no,name,score);

}

sort(stus,len);

cout<<"学生信息一览(按成绩降序):"<<endl;

for(i=0;i<len;i++)

{

stus[i].display();

}

}

运行结果:

⑷ 定义一个学生类,包含学号、姓名、平时成绩和考核成绩四个数据成员和以下成员方法(用python语言):

花了不少时间写的,挺详细的,希望采纳。


#引入operator模块,用于给集合排序
importoperator


#单行注释用"#",多行注释用'''注释内容'''
#定义一个学生类,类名用驼峰命名法
classStudent:

#构造方法,可用来创建对象格式def__init__(self,参数)参数个数自已定义,类型系统自动识别
def__init__(self,stu_no,name,base_score,exam_score):
self.stu_no=stu_no#对象属性赋值
self.name=name
self.base_score=base_score
self.exam_score=exam_score

#定义计算总评函数定义函数格式def函数名(self,参数),self代表本对象
defget_last_score(self):
#return指定返回值,无return表示此函数无返回值
returnself.base_score*0.3+self.exam_score*0.7

#类似toString方法,打印对象时,调用对象的该方法
def__str__(self):
return'学号:'+self.stu_no+'姓名:'+self.name+",平时成绩:"+str(self.base_score)+",考核成绩:"+str(self.exam_score)


#定义函数,将对象集合写到文件,上面三个函数有缩进,属于Student类的函数,本函数属于全局函数
defprint_to_file(path,stu_arr):
#打开文件,操作完成后自动关闭文件
withopen(path,'w')asfile:
#调用operator给集合排序
sort_attr=operator.attrgetter('stu_no')#指定排序属性
stu_arr.sort(key=sort_attr)#排序
forstuinstu_list:
str=stu.__str__()#将对象转换为字符串
file.write(str+' ')#将字符串写入文件


#主函数,运行的入口
if__name__=='__main__':
#创建几个学生对象,按__init__的顺序输入参数
s1=Student('1001','zhangsan',31,69)
s2=Student('1003','wangwu',28,32)
s3=Student('1004','zhaoliu',77,78)
s4=Student('1002','lisi',19,89)
#创建集合
stu_list=[s1,s2,s3,s4]

#文件路径
f='d:\aaa.txt'
print_to_file(f,stu_list)

⑸ python 求大神解答

##注意:最左边每个=表示一个空格
stus=[]
n=input('Please input the number of students:')
for i in range(int(n)):
====nm=input("Please input student's name:")
====gd=input("Please input student's gender:")
====stus.append({'name':nm,'gender':gd})
print("{} students'information has been input".format(n))
print(stus)

⑹ 下面我写的python哪错了

#coding:utf-8

importrandom
importmath

#代表宿舍,每个宿舍有两个可用的隔间
dorms=['zeus','athena','hercules','bacchus','pluto']

#代表学生及其首选和次选
prefs=dict([
('toby',('bacchus','hercules')),
('steve',('zeus','pluto')),
('andrea',('athena','zeus')),
('sarah',('zeus','pluto')),
('dave',('athena','bacchus')),
('jeff',('hercules','pluto')),
('fred',('pluto','athena')),
('suzie',('bacchus','hercules')),
('laura',('bacchus','hercules')),
('neil',('hercules','athena'))
])

person_dom_index={}

defgetsolution(dorms,prefs,result={}):
#按学生选择的房间分组
subresult={}
forstu,selectioninprefs.items():
dom=selection[0]
ifdomnotindorms:
continue
subresult.setdefault(dom,[]).append(stu)
fordom,stusinsubresult.items():
random.shuffle(stus)
while1:
stu=stus.pop(0)
prefs.pop(stu)
result.setdefault(dom,[]).append(stu)
iflen(result[dom])==2:
#房间满员
dorms.pop(dorms.index(dom))
break
ifnotstus:
#无其他学生选择
break
returnresult

#按学生首选意愿分配宿舍
sol=getsolution(dorms,prefs)
#未分配的学生
#按学生次选意愿分配宿舍
prefs_=dict([(p,x[1:])forp,xinprefs.items()])
ifprefs:
sol=getsolution(dorms,prefs,sol)

#剩余宿舍学生随机调配
random.shuffle(dorms)
prefs=prefs.keys()
random.shuffle(prefs)
fordom,stuinzip(dorms,prefs):
sol[dom].append(stu)

print" ##按宿舍展示结果##"
fordom,stusinsorted(sol.items()):
print"%10s:%r"%(dom,stus)

print" ##按学生展示结果##"
fordom,stusinsorted(sol.items()):
forstuinstus:
print"%10s:%s"%(stu,dom)

>python-u"tester.py"

###按宿舍展示结果##
#athena:['andrea','dave']
#bacchus:['toby','suzie']
#hercules:['neil','jeff']
#pluto:['fred','laura']
#zeus:['steve','sarah']
#
###按学生展示结果##
#andrea:athena
#dave:athena
#toby:bacchus
#suzie:bacchus
#neil:hercules
#jeff:hercules
#fred:pluto
#laura:pluto
#steve:zeus
#sarah:zeus
#>Exitcode:0Time:0.025

换个思路看看

⑺ python 求平均年龄

用到print字符串小数点方法

n = int(input())
stus = []
num = 0
for i in range(0, n):
temp = int(input())
stus.append(temp)
num += temp
pass
print("%.2f"%(num / n))

⑻ 属于国家保护的野生动物

国家一级重点保护野生动物中华鲟生存处境仍然堪忧。这是中国水产科学研究院长江水产研究所所长张显良研究员25日在中国自然科学博物馆协会水族馆专业委员会2006年年会暨北京海洋馆第二届国际学术交流会上透露的。

中华鲟在海洋中生长发育,在江河中产卵繁殖,江河产卵孵化的幼鲟和产后亲鲟又洄游至海洋栖息和肥育,是一种典型的溯河产卵洄游鱼类。

据张显良介绍,葛洲坝截流前,中华鲟产卵场分布在长江上游600公里江段。1981年葛洲坝截流后,中华鲟被滞留在坝下。20多年的监测表明,葛洲坝截流以后,在葛洲坝下游江段仅发现一处中华鲟产卵场,且江段长度仅7公里,面积相当狭小。“再加上近年来经济建设高速发展,人类活动加剧,水域水质污染日趋严重,导致中华鲟的资源状况逐渐衰退。”根据长江水产研究所的调查,每年洄游至长江的中华鲟产卵群体数量,已从葛洲坝截流初期的约2176尾,下降到目前的每年500尾左右。

“中华鲟自然种群数量逐年下降的趋势并没有得到根本缓解,中华鲟的保护还面临着许多问题。”张显良说,中华鲟分布较广,管理难度大,以及水利工程建设、水质污染、长江及近海密集渔捞等问题近期无法完全消除,是造成这一现象的客观因素。此外,我国每年投入中华鲟保护的资金有限,人工繁殖中华鲟产后亲鲟的恢复等困扰人们多年的难题,因设施条件限制无法着手解决,一些有效保护措施也因资金限制而无法正常开展。探索更多的保护技术和方法,寻找更多的保护途径,是加强中华鲟物种保护的必由之路。

⑼ python如何读取excel文件

1.首先说明我是使用的python3.5,我的office版本是2010,首先打开dos命令窗,安装必须的两个库,命令是:

pip3 install xlrd

Pip3 install xlwt

2.准备好excel,例如我的一个工作文件,我放在D盘/网络经验/11.xlsx,只有一个页签A,内容是一些销售数据

3.打开pycharm,新建一个excel.py的文件,首先导入支持库

import xlrdimport xlwt

4.针对刚入门的新手,先介绍三个知识,第一个:获取excel的sheet名称,第二:获取excel行数与列数,第三:获取第几行第几列的具体值,这是最常用的三个知识点

5.贴出代码,具体分析:

(1)要操作excel,首先得打开excel,使用open_workbook(‘路径’)

(2)要获取行与列,使用nrows(行),ncols(列)

(3)获取具体的值,使用cell(row,col).value

workbook=xlrd.open_workbook(r'E:11.xlsx')print (workbook.sheet_names()) sheet2=workbook.sheet_by_name('A') nrows=sheet2.nrows ncols=sheet2.ncols print(nrows,ncols) cell_A=sheet2.cell(1,1).value print(cell_A)

6.要在excel里写入值,就要使用write属性,重点说明写入是用到xlwt这个支援库,思路是先新建excel,然后新建页签B,然后将一组数据写入到B,最后保存为excel.xls,这里建议保存为2003的格式,大部分电脑都能打开,特别注意保存的excel的路径是在python工作文件的目录下面,贴出代码:

stus = [['年', '月'], ['2018', '10'], ['2017', '9'], ['2016', '8']]Excel = xlwt.Workbook() # 新建excelsheet = Excel.add_sheet('B') #新建页签Brow = 0for stu in stus: col = 0 for s in stu: sheet.write(row, col, s) #开始写入 col = col + 1 row = row + 1Excel.save('Excel.xls') #保存

关于python如何读取excel文件,青藤小编就和您分享到这里了。如果您对python编程有浓厚的兴趣,希望这篇文章可以为您提供帮助。如果您还想了解更多关于python编程的技巧及素材等内容,可以点击本站的其他文章进行学习。

⑽ 求解Python,感谢大神

keyword=input('请输入三位数的正整数:')

iflen(keyword)!=3:

print('-1')

else:

print(int(keyword[::-1]))

阅读全文

与stus在python相关的资料

热点内容
e4a写的app怎么装苹果手机 浏览:199
海立压缩机海信系 浏览:208
社保如何在app上合并 浏览:220
小米加密照片后缀 浏览:234
我的世界网易手机怎么创服务器 浏览:978
载入单页源码 浏览:930
阿里云服务器seo 浏览:777
海洋斗什么时候上线安卓 浏览:86
中行app如何查每日汇款限额 浏览:840
输入服务器sn是什么意思 浏览:725
sha1算法java 浏览:90
asp代码压缩 浏览:851
按键压枪源码 浏览:180
福建服务器负载均衡是什么 浏览:697
算法将所有的岛屿连通 浏览:313
51单片机40引脚是什么 浏览:536
手机文件夹大小怎么调节 浏览:309
android自定义日期选择器 浏览:658
租服务器要看什么 浏览:164
Lightroom文件夹移动以后 浏览:968