作业求救
老师布置的c语言作业,我想尝试用新学的Py解题。
尝试失败
{:10_286:} 如何在同一行中读取两个变量(是的我连这个也不会) 你可以参考一下这个例子>>> input().split()
1 2
['1', '2']
>>> a, b = input().split()
1 2
>>> a
'1'
>>> b
'2'
>>> def __getitem__(self, key):
return self.data
N, c = input().split()
n = int(N)
dict1 = {}
xm = ""
cj = 0
score = []
for i in range(n):
temp = input()
for ii in temp:# 读取每行字符串
if '0' <= ii <= '9':
cj = cj * 10 + int(ii)
elif ii == ' ':
score = score + cj
cj = 0
else:
xm = xm + ii
dict1 = score
xm = ""
x = input()# 读取奖学金分段
i = 1
g = []
index = 0
for t in x:
if '0' <= t <= '9':
index = index * 10 + int(t)
elif t != ' ':
g = index
index = 0
i += 1
name = input()
i = 0
for item in dict1.items():
if item == name:
cj = dict1.get(name)
pm = 1
for value in dict1.values():
if value > cj:
pm += 1
jxj = ""
if pm / n < g / 100:
jxj = "1"
elif pm / n < g / 100:
jxj = "2"
elif pm / n < g / 100:
jxj = "3"
else:
jxj = "NO"
print("%d/%d,%s" % (pm, n, jxj))
为何抛出列表超程?第一个循环只执行了一次就不行了 本帖最后由 梦难醒 于 2022-12-11 20:22 编辑
#设定总人数
num = int(input('当前录入科目为C,请输入学生人数:'))
#输入学生信息
a = ()
b = ()
for i in range(num):
name = input('姓名:')
garde = int(input('分数:'))
a += (name,)
b += (garde,)
c = sorted(b,reverse=True)
#奖学金发放比例
G1 = int(input('请输入获得一等奖学金的学生比例(%):'))
G2 = int(input('请输入获得二等奖学金的学生比例(%):'))
G3 = int(input('请输入获得三等奖学金的学生比例(%):'))
#输入查询学生姓名然后输出结果
while 1:
Name = input('请输入想要查询的学生姓名')
if Name == '退出':
break
else:
if Name not in a:
print('姓名错误,请重新输入')
else:
rank = c.index(b)
print(rank+1,'/',num,end = ',')
if rank <= num * G1 / 100:
print('一等奖学金')
elif rank <= num*G2/100:
print('二等奖学金')
elif rank <= num*G3/100:
print('三等奖学金')
else:
print('NO')
我也是刚开始学的,不造这个是不是你说的那个意思 梦难醒 发表于 2022-12-11 20:14
我也是刚开始学的,不造这个是不是你说的那个意思
感谢大佬{:10_286:}
页:
[1]