In this example , you have to take number of students as input , then ask marks for three subjects as 'Physics', 'Maths', 'History', if the total number for any student is less 120 then print he failed, or else say passed.
#!/usr/bin/env python
n = int(raw_input("Enter the number of students:"))
data = {} # here we will store the data
languages = ('Physics', 'Maths', 'History') #all languages
for i in range(0, n): #for the n number of students
name = raw_input('Enter the name of the student %d: ' % (i + 1)) #Get the name of the student
marks = []
for x in languages:
marks.append(int(raw_input('Enter marks of %s: ' % x))) #Get the marks for languages
data[name] = marks
for x, y in data.iteritems():
total = sum(y)
print "%s 's total marks %d" % (x, total)
if total < 120:
print "%s failed :(" % x
else:
print "%s passed :)" % yThe output
[kd@kdlappy book]$ ./students.py Enter the number of students:2 Enter the name of the student 1: Babai Enter marks of Physics: 12 Enter marks of Maths: 45 Enter marks of History: 40 Enter the name of the student 2: Ria Enter marks of Physics: 89 Enter marks of Maths: 98 Enter marks of History: 40 Babai 's total marks 97 Babai failed :( Ria 's total marks 227 Ria passed :)