Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8dcb0b7

Browse files
committedMar 25, 2017
initial commit
0 parents  commit 8dcb0b7

File tree

14 files changed

+238
-0
lines changed

14 files changed

+238
-0
lines changed
 

‎ex00/hello.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
####################################
2+
# hello.py
3+
#
4+
# The simplest program there is!
5+
####################################
6+
7+
print("Hello, world!")

‎ex01/string0.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
####################################
2+
# string0.py
3+
#
4+
# Introduce importing libraries (modules)
5+
# Introduce variable printing
6+
####################################
7+
8+
import cs50
9+
10+
name = cs50.get_string()
11+
print("Hello, {}!".format(name))

‎ex01/string1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
####################################
2+
# string1.py
3+
#
4+
# Introduce specific function importing
5+
####################################
6+
7+
from cs50 import get_string
8+
9+
print("What is your name?" )
10+
name = get_string()
11+
print("Hello, {}!".format(name))

‎ex02/temperature.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
####################################
2+
# temperature.py
3+
#
4+
# Introduce mathematical operations
5+
# Introduce formatted printing
6+
####################################
7+
8+
from cs50 import get_float
9+
10+
print("What temperature is it in Fahrenheit?")
11+
fahrenheit = get_float()
12+
13+
# formula for conversion is (f - 32) * (5/9)
14+
15+
celsius = 5.0 / 9.0 * (fahrenheit - 32.0)
16+
17+
# print my floating point number (f) to one decimal place (1)
18+
print("{:.1f}".format(celsius))

‎ex03/conditions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
####################################
2+
# conditions.py
3+
#
4+
# Introduce decision making
5+
####################################
6+
7+
import cs50
8+
9+
print("Give me an integer, please!")
10+
i = cs50.get_int()
11+
12+
# if the condition is true, execute the indented lines of code
13+
if i < 0:
14+
print("negative")
15+
16+
# "elif" is the way one says "else if"
17+
elif i > 0:
18+
print("positive")
19+
20+
# else is the catch-all
21+
else:
22+
print("zero")

‎ex04/logical.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
####################################
2+
# logical.py
3+
#
4+
# Introduce Boolean concepts (or, and)
5+
####################################
6+
7+
import cs50
8+
9+
print("Answer yes (y/Y) or no (n/N)")
10+
c = cs50.get_char()
11+
12+
if c == "Y" or c == "y":
13+
print("yes")
14+
elif c == "N" or c == "n":
15+
print("no")
16+
else:
17+
print("error")

‎ex05/quack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
####################################
2+
# quack.py
3+
#
4+
# Introduce other libraries/modules
5+
# Introduce looping
6+
####################################
7+
8+
import time
9+
10+
while True:
11+
print("Quack!")
12+
time.sleep(1)

‎ex06/string2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
####################################
2+
# string2.py
3+
#
4+
# Introduce a new kind of loop
5+
# Introduce the concept of "None"/null
6+
####################################
7+
8+
import cs50
9+
10+
print("Please provide some text!")
11+
s = cs50.get_string()
12+
13+
if s != None:
14+
for c in s:
15+
print(c)

‎ex07/count.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
####################################
2+
# count.py
3+
#
4+
# Introduce range() for counting
5+
####################################
6+
7+
import cs50
8+
9+
print("Please give me an integer!")
10+
value = cs50.get_int()
11+
12+
for i in range(value):
13+
print(i + 1)

‎ex08/positive.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
####################################
2+
# positive.py
3+
#
4+
# Introduce the concept of functions
5+
# Introduce the concept of main
6+
# Bring it all together?
7+
####################################
8+
9+
import cs50
10+
11+
def get_positive_int():
12+
# continue looping forever
13+
while True:
14+
15+
# prompt the user for input using CS50's get_int function
16+
print("n is ", end="")
17+
n = cs50.get_int()
18+
19+
# if we get a positive integer, break out of the loop
20+
if n > 0:
21+
break
22+
23+
# return a value from this function back to the user
24+
return n
25+
26+
def main():
27+
28+
i = get_positive_int()
29+
print("{} is a positive integer".format(i))
30+
31+
32+
33+
if __name__ == "__main__":
34+
main()

‎greedy/greedy.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
####################################
2+
# greedy.py
3+
#
4+
# Provide change to a user, using
5+
# only coins of values: 25c, 10c, 5c, 1c
6+
####################################
7+
8+
# import any necessary modules
9+
10+
# ask the user for change in dollars and cents
11+
12+
# convert from dollars and cents to cents only
13+
14+
# give the user one coin at a time, taking the biggest piece possible
15+
16+
# print out how many coins we gave

‎stairs/stairs.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
####################################
2+
# stairs.py
3+
#
4+
# Build a right-align set of stairs of
5+
# the specified height and width
6+
#
7+
# Example (height 3):
8+
# x
9+
# xx
10+
# xxx
11+
#
12+
# Example (height 5):
13+
#
14+
# x
15+
# xx
16+
# xxx
17+
# xxxx
18+
# xxxxx
19+
####################################
20+
21+
# import any necessary modules
22+
23+
# prompt the user for a height in [0, 23] (re-prompting if needed!)
24+
25+
# print the stairs!
26+
27+
## HINTS:
28+
## 1. You'll probably find it easiest to print a full square of x's first
29+
## 2. Try and print a left-aligned set of stairs next... you'll probably find it easier!
30+
## 3. Then think about what else you could print to make things right-aligned!
31+
## 4. We teach a similar problem to this in CS50 called "Mario". The below video teaches the concepts in a programming
32+
## language called 'C', but the same basic ideas in that walkthrough are still relevant, just using Python instead!
33+
## Walkthrough: https://www.youtube.com/watch?v=EGWRG5e1O2s

‎web/application.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask import Flask, render_template
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/")
6+
def index():
7+
return "You are at the index!"
8+
9+
@app.route("/sample")
10+
def sample():
11+
return "You have reached the sample page!"
12+
13+
@app.route("/search")
14+
def search():
15+
return render_template('search.html')

‎web/templates/search.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<title>CS50 Search</title>
4+
</head>
5+
<body>
6+
<div>
7+
<form action="https://www.google.com/search" method="get">
8+
<input name="q" type="text"/>
9+
<br/>
10+
<input type="submit" value="CS50 Search"/>
11+
</form>
12+
</div>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.