Posted to tcl by mjanssen at Fri Jul 23 09:35:24 GMT 2021view raw
- set grades {Peter B
- Celine A-
- Zsófia B+
- João F
- Maryam B+
- Àñ B-
- Finn D+
- Aarav A
- Emma F
- Omar B}
- package require sqlite3
- sqlite3 db :memory:
- db eval {CREATE TABLE grades(name TEXT PRIMARY KEY, grade TEXT, naked_grade TEXT)}
- foreach {name grade} $grades {
- if {![regexp {[A-F][+-]?} $grade]} {
- puts "Can't parse pair '$name $grade'"
- exit 1
- }
- db eval {INSERT INTO grades VALUES ($name, $grade, trim($grade, '+-') )}
- }
- puts "Zsófia's grade: [db eval {SELECT grade FROM grades WHERE name='Zsófia'}]"
- puts "List of students with a failing grade:"
- puts " [join [
- db eval {SELECT name FROM grades WHERE grade >= 'E' ORDER BY grade}
- ] {, }]"
- db eval {select naked_grade, count(*) from grades group by naked_grade}