I have the following code:
l=[]
n=int(input('enter number of list'))
[[] for i in range (n)]
for i in range (1, n+1):
m=input('enter student')
l.append(m)
n=int(input('enter number of grades'))
for i in range (1, n+1):
y=int(input('enter grade'))
l.append(y)
s = ''.join(str(l))
print (*l,sep='')
and I would like to represent the input data as the following data:
I believe what you want to do is the following:
n=int(input('enter number of students'))
l=[]
for i in range (n):
m=input('enter student name:')
l.append([m])
x=int(input(f'enter number of grades for {m}:'))
for j in range (x):
y=float(input(f'enter grade {j+1} for {m}:'))
l[i].append(y)
print(*l,sep=' ')
With the following input you'll get:
enter number of students>? 2
enter student name:>? fdkfsd
enter number of grades for fdkfsd:>? 2
enter grade 1 for fdkfsd:>? 1.2
enter grade 2 for fdkfsd:>? 3.3
enter student name:>? sdsa
enter number of grades for sdsa:>? 3
enter grade 1 for sdsa:>? 34.5
enter grade 2 for sdsa:>? 43.2
enter grade 3 for sdsa:>? 12.2
['fdkfsd', 1.2, 3.3] ['sdsa', 34.5, 43.2, 12.2]
However, I would recommend using pandas.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.