Skip to content

Commit

Permalink
Add mario and greedy in python
Browse files Browse the repository at this point in the history
  • Loading branch information
ks927 committed Oct 26, 2017
1 parent 7f008f2 commit f1ce667
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pset1/mario.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cs50.h>
1#include <cs50.h>
#include <stdio.h>


Expand Down
37 changes: 37 additions & 0 deletions pset6/greedy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
while True:
cString = input("How much change? ")
change = float(cString)
if change >= 0:
break

count = 0
balance = change*100
quarter = 25
dime = 10
nickel = 05
penny = 01

while True:
# Quarter
if balance - quarter >= 0:
count += 1
balance = balance-quarter

# Dime
elif balance - dime >= 0:
count += 1
balance = balance-dime

# Nickel
elif balance - nickel >= 0:
count += 1
balance = balance-nickel

# Penny
elif balance - penny >= 0:
count += 1
balance = balance-penny

if balance <= 0:
break
print count
13 changes: 13 additions & 0 deletions pset6/mario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
while True:
hString = input("Enter height of pyramid: ")
height = int(hString)
if height > 0 and height <= 23:
break
space = " "
hash = "#"
for i in range(height):
print(space*(height-i) + hash*(i+2))
height -= 1



0 comments on commit f1ce667

Please sign in to comment.