Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
5 views
in Python by (16.4k points)

Hello, all. I have a query. I need to execute a code that allows you to input five student's names and their marks. Every time, When I run it, It's not accepting the student's name.

students=[]

for num in range(5):

    x=input("Enter name of students: ")

    students.append(x)

marks=[]

for num in range(5):

    y=input("Enter marks of students:")

    marks.append(y)

report = input("Do you want to print class report?: ")

if report == 'yes':

    print(x[0],":", y[0])

    print(x[1],":", y[1])

    print(x[2],":", y[2])

    print(x[3],":", y[3])

    print(x[4],":", y[4])

1 Answer

0 votes
by (26.4k points)

Working code:

n = 5

students=[]

for num in range(n):

    x=raw_input("Enter name of students: ")

    students.append(x)

marks=[]

for num in range(n):

    y=raw_input("Enter marks of students:")

    marks.append(y)

report = raw_input("Do you want to print class report?: ")

if report == 'yes':

    for i,j in zip(students, marks):

        print(i,':', j)

Here, you have to use list.append, zip with loop to cycle through pairs of data and raw_input in the place of input in Python 2.x

Want to learn more about python? Come and Join: python training course

For more details, do check out..

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...