Issues with a college assignment using Python

creating dictionary isn’t that tough, its as simple as creating list, which you have already done

For list

  mylist = []
  #for dictionary
  mydictionary = {}

Adding item into dictionary

  mydictionary["fail"] = 50 

Iterating the list

 for item in mylist:
     print item

Iterating in dictionary

 for key,value in mydictionary.iteritem():
     print key,value

I hope this helps you, there might be mistake in iteritem spelling etc you could google it but thats how its done normally

here is updated thing

 mydictionary = {}

 marks = 0

 mydictionary[(0,45)] = "Fail"
 mydictionary[(46,59)] = "Lower"
 mydictionary[(60,69)] = "Second Lower"
 mydictionary[(70,100)] = "First"

 marks = 63

 for key,value in mydictionary.iteritems():
     if marks >= key[0] and marks <= key[1]:
         print value

The given code works you could also do it in this way though

Browse More Popular Posts

Leave a Comment