Advertisement
eranseg

ex1

Mar 15th, 2020
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.12 KB | None | 0 0
  1. var grades:[String:Int] = ["Eran":100,"Eli":95,"Shlomi":15,"Nissim":30,"Ohad":93,"Moshe":96,"Danny":85,"Yaron":78]
  2.  
  3. var bottomGrade : Int = 100
  4. var topGrade : Int = 0
  5. var sum : Int = 0
  6. var topName : String = ""
  7. var bottomName : String = ""
  8. var i = 0
  9. var j = 0
  10. var topList:[String] = []
  11. var bottomList:[String] = []
  12. for student in grades {
  13.     sum += student.value
  14.     if student.value > 95 {
  15.         topList.append(student.key)
  16.     }
  17.     if student.value < 55 {
  18.         bottomList.append(student.key)
  19.     }
  20.     if student.value > topGrade {
  21.         topGrade = student.value
  22.         topName = student.key
  23.     }
  24.     if student.value < bottomGrade {
  25.         bottomGrade = student.value
  26.         bottomName = student.key
  27.     }
  28. }
  29.  
  30. print("\(topName) has the highest grade - \(topGrade)")
  31. print("\(bottomName) has the lowest grade - \(bottomGrade)")
  32. print("Failed students names:")
  33. for s in bottomList {
  34.     if grades.keys.contains(s) {
  35.         print(s)
  36.     }
  37. }
  38. print("Best students names:")
  39. for s in topList {
  40.     if grades.keys.contains(s) {
  41.         print(s)
  42.     }
  43. }
  44. print("average - \(sum/grades.count)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement