-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f33d07e
commit 6855134
Showing
13 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/adieu/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import inflect | ||
|
||
p = inflect.engine() | ||
|
||
names = [] | ||
while True: | ||
try: | ||
names.append(input("Name: ")) | ||
except EOFError: | ||
break | ||
|
||
print(f"\nAdieu, adieu, to {p.join(names)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/bitcoin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
|
||
import requests | ||
|
||
if len(sys.argv) != 2: | ||
sys.exit("Missing command-line argument") | ||
|
||
try: | ||
bitcoin = float(sys.argv[1]) | ||
except ValueError: | ||
sys.exit("Command-line argument is not a number") | ||
|
||
|
||
try: | ||
response = requests.get( | ||
"https://api.coindesk.com/v1/bpi/currentprice.json", timeout=1 | ||
) | ||
except (requests.RequestException, requests.Timeout) as error: | ||
sys.exit(f"Request error:\n{error}") | ||
|
||
bitcoin_rate = response.json()["bpi"]["USD"]["rate_float"] | ||
print(f"${bitcoin_rate * bitcoin:,.4f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/emojize/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from emoji import emojize | ||
|
||
emoji_input = input("Input: ") | ||
print(f"Output: {emojize(emoji_input, language='alias')}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/figlet/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
from random import choice | ||
|
||
from pyfiglet import Figlet | ||
|
||
|
||
def main(): | ||
figlet = Figlet() | ||
|
||
if len(sys.argv) != 1 and len(sys.argv) != 3: | ||
print("Invalid usage") | ||
sys.exit(1) | ||
if len(sys.argv) == 3: | ||
is_invalid_font_flag = sys.argv[1] != "-f" and sys.argv[1] != "--font" | ||
is_invalid_font_name = sys.argv[2] not in figlet.getFonts() | ||
if is_invalid_font_flag or is_invalid_font_name: | ||
print("Invalid usage") | ||
sys.exit(1) | ||
|
||
font = get_font_choice(figlet) | ||
my_string = input("Input: ") | ||
figlet.setFont(font=font) | ||
|
||
print(figlet.renderText(my_string)) | ||
|
||
|
||
def get_font_choice(figlet): | ||
if len(sys.argv) == 3: | ||
return sys.argv[2] | ||
return choice(figlet.getFonts()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/game/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import random | ||
|
||
while True: | ||
try: | ||
level = int(input("Level: ")) | ||
if level > 0: | ||
break | ||
except ValueError: | ||
pass | ||
|
||
answer = random.randint(1, level) | ||
|
||
while True: | ||
try: | ||
guess = int(input("Guess: ")) | ||
if guess < answer: | ||
print("Too small!") | ||
elif guess > answer: | ||
print("Too large!") | ||
else: | ||
print("Just right!") | ||
break | ||
except ValueError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cs50.harvard.edu/python/2022/psets/4/professor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import random | ||
|
||
|
||
def main(): | ||
score = 0 | ||
level = get_level() | ||
problems = [generate_integer(level) for _ in range(10)] | ||
|
||
for problem in problems: | ||
tries = 0 | ||
while True: | ||
print(f"{problem[0]} + {problem[1]} = ", end="") | ||
try: | ||
answer = int(input()) | ||
if problem[0] + problem[1] != answer: | ||
raise ValueError | ||
score += 1 | ||
break | ||
except ValueError: | ||
print("EEE") | ||
tries += 1 | ||
if tries == 3: | ||
print(f"{problem[0]} + {problem[1]} = {problem[0] + problem[1]}") | ||
break | ||
|
||
print(f"Score: {score}") | ||
|
||
|
||
def get_level(): | ||
while True: | ||
try: | ||
level = int(input("Level: ")) | ||
if level in range(1, 4): | ||
return level | ||
except ValueError: | ||
pass | ||
|
||
|
||
def generate_integer(level): | ||
if level == 1: | ||
return random.randint(0, 9), random.randint(0, 9) | ||
elif level == 2: | ||
return random.randint(10, 99), random.randint(10, 99) | ||
else: | ||
return random.randint(100, 999), random.randint(100, 999) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters