diff --git a/Introduction to Computer Science/README.md b/Introduction to Computer Science/README.md index 3748c2d..5640027 100644 --- a/Introduction to Computer Science/README.md +++ b/Introduction to Computer Science/README.md @@ -1,12 +1,12 @@ -# Introduction to Computer Science - CS50 -by Harvard University - - -# Syllabus -Introduction to the intellectual enterprises of computer science and the art of programming. This course teaches students how to think algorithmically and solve problems efficiently. Topics include abstraction, algorithms, data structures, encapsulation, resource management, security, and software engineering. Languages include C, Python, and SQL plus students’ choice of: HTML, CSS, and JavaScript (for web development); Java or Swift (for mobile app development); or Lua (for game development). Problem sets inspired by the arts, humanities, social sciences, and sciences. Course culminates in a final project. Designed for concentrators and non-concentrators alike, with or without prior programming experience. Two thirds of CS50 students have never taken CS before. Among the overarching goals of this course are to inspire students to explore unfamiliar waters, without fear of failure, create an intensive, shared experience, accessible to all students, and build community among students. - -Following the online course: - -https://www.edx.org/course/cs50s-introduction-to-computer-science# - -https://cs50.harvard.edu/x/2020/ +# Introduction to Computer Science - CS50 +by Harvard University + + +# Syllabus +Introduction to the intellectual enterprises of computer science and the art of programming. This course teaches students how to think algorithmically and solve problems efficiently. Topics include abstraction, algorithms, data structures, encapsulation, resource management, security, and software engineering. Languages include C, Python, and SQL plus students’ choice of: HTML, CSS, and JavaScript (for web development); Java or Swift (for mobile app development); or Lua (for game development). Problem sets inspired by the arts, humanities, social sciences, and sciences. Course culminates in a final project. Designed for concentrators and non-concentrators alike, with or without prior programming experience. Two thirds of CS50 students have never taken CS before. Among the overarching goals of this course are to inspire students to explore unfamiliar waters, without fear of failure, create an intensive, shared experience, accessible to all students, and build community among students. + +Following the online course: + +https://www.edx.org/course/cs50s-introduction-to-computer-science# + +https://cs50.harvard.edu/x/2020/ diff --git a/Introduction to Computer Science/Week 6/hello.py b/Introduction to Computer Science/Week 6/hello.py index c5e6922..474ef3d 100644 --- a/Introduction to Computer Science/Week 6/hello.py +++ b/Introduction to Computer Science/Week 6/hello.py @@ -1,5 +1,5 @@ - -from cs50 import get_string - -inp = get_string("What is your name?\n") + +from cs50 import get_string + +inp = get_string("What is your name?\n") print(f"hello, {inp}") \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/houses/import.py b/Introduction to Computer Science/Week 7/houses/import.py index 4640904..fbbbf1a 100644 --- a/Introduction to Computer Science/Week 7/houses/import.py +++ b/Introduction to Computer Science/Week 7/houses/import.py @@ -1 +1,34 @@ # TODO + +from sys import argv +from cs50 import SQL +import csv + + + +db = SQL("sqlite:///students.db") +db.execute("DELETE FROM students") + +if len(argv) != 2: + print("Err") + exit(1) + +with open(argv[1], "r") as csvFile: + csvReader = csv.DictReader(csvFile) + + r = 0 + for row in csvReader: + spli = row["name"].split() + + nf = spli[0] + if len(spli) == 2: + nm = None + nl = spli[1] + else: + nm = spli[1] + nl = spli[2] + + db.execute("INSERT INTO students (id, first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?, ?)", r, nf, nm, nl, row["house"], row["birth"]) + r += 1 + + diff --git a/Introduction to Computer Science/Week 7/houses/roster.py b/Introduction to Computer Science/Week 7/houses/roster.py index 0d0c8ca..ce130f7 100644 --- a/Introduction to Computer Science/Week 7/houses/roster.py +++ b/Introduction to Computer Science/Week 7/houses/roster.py @@ -2,9 +2,6 @@ from sys import argv from cs50 import SQL -import csv - - db = SQL("sqlite:///students.db") @@ -12,23 +9,12 @@ if len(argv) != 2: print("Err") exit(1) -with open(argv[1], "r") as csvFile: - csvReader = csv.DictReader(csvFile) - - r = 0 - for row in csvReader: - spli = row["name"].split() - - nf = spli[0] - if len(spli) == 2: - nm = "" - nl = spli[2] - else: - nm = spli[2] - nl = spli[3] - - db.execute("INSTERT INTO students (id first middle last house birth) VALUES (? ? ? ? ? ?)", - r, spli[0], spli[1], spli[2], row["house"], row["birth"]) - r += 1 +hname = argv[1] +students = db.execute("SELECT * FROM students WHERE house LIKE ? ORDER BY last ASC, first ASC", hname) +for s in students: + print(s["first"], end=" ") + if s["middle"]: + print(s["middle"], end=" ") + print(f"{s['last']}, born {s['birth']}") diff --git a/Introduction to Computer Science/Week 7/houses/students.db b/Introduction to Computer Science/Week 7/houses/students.db index bef57ebd08193df556c8d503779c5e50d7405ec4..c2feb8d02f4e791425e63891ca5a3112cfdbc8d5 100644 GIT binary patch literal 12288 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCV6b3dU|?oI07eD|1{MUD0mMh*Vr5z| z=$R<+GB7YO@!ewJ*WtT`Rn@5AXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeD zkR1X6Ol;!X+KiDUiAg!B#f3SUC8_bnsfDGfdCBNpX6GPR#}HSA5Jx8;R|Pb+8hMGi zsXE1}g_@0ljO^mFvW!io5Hm|kQ&RIvii@E%6RIgtQ3VYy1qB6#%oGJrzYte<*C2&} zAWvV%phyL8*GL7&&=7x5Kj$DHM6BvF@=J>m$_)*m#w2AHm1Mx&!leo7n`>~bVc@^Vzn_0Le>Hz3zb(HE-(S8P zd|UW>_;UEX`P6v-@!sa$$lK3b$Q#J3!^_L_g6BBTLY``#SRQL0Def=am$)}`Pv*|% z_Tbj!=HzM=ok5&e zRGuj$wWz4lDL=m?D6uRxFF7Z%oPCd+3dnGf-qa#c7r`SlJsnB&ZdqlJW^qNP;L_s6 zJg5A;)MAg)w6vVmg3`1!_T7p~Agg5+nSxUjb4!ceGV}5>(-ZUDiz?I7GV@aMi`aLo zDY7$2N=hp-1?A@@=A<}f=46%@ho>eM=cHC5soNu`0CI^aNL_AbPD)}}VqPke{9ajk zkV_=xnS%1uQ;R^JOf5!uWS4>**d-w8q|~AkkIbB$%*3J;goy}ODxF@NG!?BL2}1#1!<5w7swUS1qzmLy13az)FVQEzEHynpA1Uzn$_RnvCFPlXGK&*K zN{b3I^AIlBtsn?;rnn-L4=81(q!u|9<(KCng~x6U0gxND6`8zBi%T-|+%of$Gj!c@ zQcIFEa#AZ%k|aM!rMx_oXK{W~YL0JWvP*txdSVX3x;<)q>h*NePOgJ@Pyt`@o9w@)9!~lR%M) zN=?r%s&vn<%t4C8J!)L+4ASD#icIdAd8uVZiN5(cIhB|hWUmq@ z$Rc?~CfB08)Z!A~#N^z}oSeiwWV@6(*crqnCFPl1iV~CaeM*xvON)IIbJFrF5fQpa zmK_`yicBu4iFqLz`MHV3NWR`9&jyNbX+MMVZMindu-eBRO%W95YCTq&$;TPGV+pYE)uUW?m-3b-R_A zK*1$1&*Yd_l98WR>7JjHQe2XXoL=_GGJ?zymuGTJDauUD3n)!aMe^WI1qM)Zk_1Vo z<|JmOr23W?l^|!)eW3n7BmXA`{!h?Cc9a?ofzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c a4S~@R7!85Z5Eup_z{AKa%LrSupbh|x9w^KJ delta 43 qcmZojXh@hK&B!=W#+i|EW5N=CCI*4cf(j4$CpJj3@iH(lAh-Yna|=}f diff --git a/Introduction to Computer Science/Week 7/movies/10.sql b/Introduction to Computer Science/Week 7/movies/10.sql index c64ce45..656a3b2 100644 --- a/Introduction to Computer Science/Week 7/movies/10.sql +++ b/Introduction to Computer Science/Week 7/movies/10.sql @@ -1,11 +1,11 @@ -SELECT - name -FROM - movies - JOIN directors on movies.id = directors.movie_id - JOIN people on people.id = directors.person_id - Join ratings on ratings.movie_id = directors.movie_id -WHERE - rating >= 9.0 -ORDER BY +SELECT + name +FROM + movies + JOIN directors on movies.id = directors.movie_id + JOIN people on people.id = directors.person_id + Join ratings on ratings.movie_id = directors.movie_id +WHERE + rating >= 9.0 +ORDER BY birth ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/11.sql b/Introduction to Computer Science/Week 7/movies/11.sql index 8017d76..df10d13 100644 --- a/Introduction to Computer Science/Week 7/movies/11.sql +++ b/Introduction to Computer Science/Week 7/movies/11.sql @@ -1,13 +1,13 @@ -SELECT - title -FROM - movies - JOIN stars on stars.movie_id = movies.id - JOIN people on people.id = stars.person_id - Join ratings on ratings.movie_id = movies.id -WHERE - name = 'Chadwick Boseman' -ORDER BY - rating DESC -LIMIT +SELECT + title +FROM + movies + JOIN stars on stars.movie_id = movies.id + JOIN people on people.id = stars.person_id + Join ratings on ratings.movie_id = movies.id +WHERE + name = 'Chadwick Boseman' +ORDER BY + rating DESC +LIMIT 5; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/12.sql b/Introduction to Computer Science/Week 7/movies/12.sql index 434f757..3b89db6 100644 --- a/Introduction to Computer Science/Week 7/movies/12.sql +++ b/Introduction to Computer Science/Week 7/movies/12.sql @@ -1,8 +1,8 @@ -SELECT movies.title FROM people -JOIN stars ON people.id = stars.person_id -JOIN movies ON stars.movie_id = movies.id -WHERE people.name = "Johnny Depp" AND movies.title IN( -SELECT movies.title FROM people -JOIN stars ON people.id = stars.person_id -JOIN movies ON stars.movie_id = movies.id +SELECT movies.title FROM people +JOIN stars ON people.id = stars.person_id +JOIN movies ON stars.movie_id = movies.id +WHERE people.name = "Johnny Depp" AND movies.title IN( +SELECT movies.title FROM people +JOIN stars ON people.id = stars.person_id +JOIN movies ON stars.movie_id = movies.id WHERE people.name = "Helena Bonham Carter"); \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/13.sql b/Introduction to Computer Science/Week 7/movies/13.sql index 96bd1db..76739f3 100644 --- a/Introduction to Computer Science/Week 7/movies/13.sql +++ b/Introduction to Computer Science/Week 7/movies/13.sql @@ -1,16 +1,16 @@ -SELECT DISTINCT name FROM - stars - JOIN people on stars.person_id = people.id - WHERE - movie_id IN - ( - SELECT movie_id FROM stars WHERE - person_id = - ( - SELECT id FROM people WHERE - name = 'Kevin Bacon' AND birth = 1958 - ) - ) - AND name != 'Kevin Bacon' - ORDER BY name ASC -; +SELECT DISTINCT name FROM + stars + JOIN people on stars.person_id = people.id + WHERE + movie_id IN + ( + SELECT movie_id FROM stars WHERE + person_id = + ( + SELECT id FROM people WHERE + name = 'Kevin Bacon' AND birth = 1958 + ) + ) + AND name != 'Kevin Bacon' + ORDER BY name ASC +; diff --git a/Introduction to Computer Science/Week 7/movies/2.sql b/Introduction to Computer Science/Week 7/movies/2.sql index ba8de6a..8237262 100644 --- a/Introduction to Computer Science/Week 7/movies/2.sql +++ b/Introduction to Computer Science/Week 7/movies/2.sql @@ -1,5 +1,5 @@ -SELECT - birth -FROM - people +SELECT + birth +FROM + people WHERE name='Emma Stone'; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/3.sql b/Introduction to Computer Science/Week 7/movies/3.sql index ef0ad67..0b9d196 100644 --- a/Introduction to Computer Science/Week 7/movies/3.sql +++ b/Introduction to Computer Science/Week 7/movies/3.sql @@ -1,7 +1,7 @@ -SELECT - title -FROM - movies -WHERE - year>=2018 +SELECT + title +FROM + movies +WHERE + year>=2018 ORDER BY title ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/4.sql b/Introduction to Computer Science/Week 7/movies/4.sql index b5944c4..ac42bba 100644 --- a/Introduction to Computer Science/Week 7/movies/4.sql +++ b/Introduction to Computer Science/Week 7/movies/4.sql @@ -1,7 +1,7 @@ -SELECT - COUNT(title) -FROM - movies JOIN ratings on movies.id = ratings.movie_id -WHERE - rating=10.0 +SELECT + COUNT(title) +FROM + movies JOIN ratings on movies.id = ratings.movie_id +WHERE + rating=10.0 ORDER BY title ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/5.sql b/Introduction to Computer Science/Week 7/movies/5.sql index f8b812a..373c5ce 100644 --- a/Introduction to Computer Science/Week 7/movies/5.sql +++ b/Introduction to Computer Science/Week 7/movies/5.sql @@ -1,7 +1,7 @@ -SELECT - title, year -FROM - movies -WHERE - title LIKE "Harry Potter%" +SELECT + title, year +FROM + movies +WHERE + title LIKE "Harry Potter%" ORDER BY 2; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/6.sql b/Introduction to Computer Science/Week 7/movies/6.sql index cfa179a..f57fae7 100644 --- a/Introduction to Computer Science/Week 7/movies/6.sql +++ b/Introduction to Computer Science/Week 7/movies/6.sql @@ -1,7 +1,7 @@ -SELECT - AVG(rating) -FROM - movies JOIN ratings on movies.id = ratings.movie_id -WHERE - year=2012 +SELECT + AVG(rating) +FROM + movies JOIN ratings on movies.id = ratings.movie_id +WHERE + year=2012 ORDER BY title ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/7.sql b/Introduction to Computer Science/Week 7/movies/7.sql index 75ea312..85ede18 100644 --- a/Introduction to Computer Science/Week 7/movies/7.sql +++ b/Introduction to Computer Science/Week 7/movies/7.sql @@ -1,9 +1,9 @@ -SELECT - title, rating -FROM - movies JOIN ratings on movies.id = ratings.movie_id -WHERE - year = 2010 -ORDER BY - rating DESC, +SELECT + title, rating +FROM + movies JOIN ratings on movies.id = ratings.movie_id +WHERE + year = 2010 +ORDER BY + rating DESC, title ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/8.sql b/Introduction to Computer Science/Week 7/movies/8.sql index cdc74fe..b246138 100644 --- a/Introduction to Computer Science/Week 7/movies/8.sql +++ b/Introduction to Computer Science/Week 7/movies/8.sql @@ -1,10 +1,10 @@ -SELECT - name -FROM - movies - JOIN stars on movies.id = stars.movie_id - JOIN people on people.id = stars.person_id -WHERE - title = 'Toy Story' -ORDER BY +SELECT + name +FROM + movies + JOIN stars on movies.id = stars.movie_id + JOIN people on people.id = stars.person_id +WHERE + title = 'Toy Story' +ORDER BY title ASC; \ No newline at end of file diff --git a/Introduction to Computer Science/Week 7/movies/9.sql b/Introduction to Computer Science/Week 7/movies/9.sql index acbb486..f5a9f4e 100644 --- a/Introduction to Computer Science/Week 7/movies/9.sql +++ b/Introduction to Computer Science/Week 7/movies/9.sql @@ -1,10 +1,10 @@ -SELECT - name -FROM - movies - JOIN stars on movies.id = stars.movie_id - JOIN people on people.id = stars.person_id -WHERE - year = 2004 -ORDER BY +SELECT + name +FROM + movies + JOIN stars on movies.id = stars.movie_id + JOIN people on people.id = stars.person_id +WHERE + year = 2004 +ORDER BY birth ASC; \ No newline at end of file