Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var grades:[String:Int] = ["Eran":100,"Eli":95,"Shlomi":15,"Nissim":30,"Ohad":93,"Moshe":96,"Danny":85,"Yaron":78]
- var bottomGrade : Int = 100
- var topGrade : Int = 0
- var sum : Int = 0
- var topName : String = ""
- var bottomName : String = ""
- var i = 0
- var j = 0
- var topList:[String] = []
- var bottomList:[String] = []
- for student in grades {
- sum += student.value
- if student.value > 95 {
- topList.append(student.key)
- }
- if student.value < 55 {
- bottomList.append(student.key)
- }
- if student.value > topGrade {
- topGrade = student.value
- topName = student.key
- }
- if student.value < bottomGrade {
- bottomGrade = student.value
- bottomName = student.key
- }
- }
- print("\(topName) has the highest grade - \(topGrade)")
- print("\(bottomName) has the lowest grade - \(bottomGrade)")
- print("Failed students names:")
- for s in bottomList {
- if grades.keys.contains(s) {
- print(s)
- }
- }
- print("Best students names:")
- for s in topList {
- if grades.keys.contains(s) {
- print(s)
- }
- }
- print("average - \(sum/grades.count)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement