code.cs50.io
This is CS50 for MBAs.
code.cs50.io
code hello.py
print("Hello, world.")
int main(void)
{
printf("Hello, world.\n");
}
python hello.py
python hello.py
python hello.py
Interpreter
python hello.py
Interpreter
Python program
compilation
vs.
interpretation
E | 01000101 | P | 01010000 | ) | 00101001 |
H | 01001000 | R | 01010010 | " | 00100010 |
I | 01001001 | T | 01010100 | . | 00101110 |
L | 01001100 | N | 01001110 | ; | 00111011 |
O | 01001111 | ( | 00101000 | | |
tradeoffs
hello
hello.py, version 2
vertical
vertical.py, version 1
vertical.py, version 2
horizontal
horizontal.py, version 1
horizontal.py, version 2
square
square.py, version 1
square.py, version 2
square.py, version 3
square.py, version 4
mario
mario.py, for those less comfortable
mario.py, for those more comfortable
cash
1¢
5¢
10¢
25¢
Problem
Given an amount of change, what is the minimum number of coins we can use to make that change?
30¢
30¢
30 coins
30¢
3 coins
30¢
2 coins
47¢
47 cents remaining
0 coins used
47¢
0 cents remaining
5 coins used
Pseudocode
Test Cases
1¢
15¢
$1.60
-$1
1¢ →
→ 1 coin
15¢ →
→ 2 coins
$1.60 →
→ 7 coins
-$1 →
→ Reprompt
Cash
In a file called cash.py, write a program that prompts the user for how much change is owed and then prints the minimum number of coins with which that change can be made.
$ python cash.py
Change owed: 0.28
4
Distribution Code
If feeling less comfortable, in your terminal, type:
wget https://cdn.cs50.net/hbs/2022/spring/labs/1/cash/less/cash.py
followed by Enter.
If feeling more comfortable, in your terminal, type:
wget https://cdn.cs50.net/hbs/2022/spring/labs/1/cash/more/cash.py
followed by Enter.
Extra Challenge
Tolerate a $ character in the user's input
Critique
This was CS50 for MBAs.
hbs@cs50.harvard.edu