PYTHON Practice 4
PYTHON Practice 4
If the user provides two command-line arguments and the first is not -f or --font or the
second is not the name of a font, the program should exit via sys.exit with an error
message.
Hints
You can then get a list of available fonts with code like this:
figlet.getFonts()
You can set the font with code like this, wherein f is the font’s name as a str:
figlet.setFont(font=f)
And you can output text in that font with code like this, wherein s is that text as a str:
print(figlet.renderText(s))
• Note that the random module comes with quite a few func�ons, per
docs.python.org/3/library/random.html.
Guessing Game
I’m thinking of a number between 1 and 100…
What is it?
• . If the user does not input a posi�ve integer, the program should prompt again.
• Randomly generates an integer between 1 and
• Prompts the user to guess that integer. If the guess is not a posi�ve integer, the program should
prompt the user again.
• If the guess is smaller than that integer, the program should output Too small! and
prompt the user again.
• If the guess is larger than that integer, the program should output Too large! and prompt
the user again.
• If the guess is the same as that integer, the program should output Just right! and exit.
Hints
• Note that the random module comes with quite a few func�ons, per
docs.python.org/3/library/random.html.
Bitcoin Price Index
Bitcoin is a form of digi�al currency, otherwise known as
cryptocurrency. Rather than rely on a central authority like a bank,
Bitcoin instead relies on a distributed network, otherwise known as a
blockchain, to record transac�ons.
Because there’s demand for Bitcoin (i.e., users want it), users are willing to buy it, as by
exchanging one currency (e.g., USD) for Bitcoin.
• , that they would like to buy. If that argument cannot be converted to a float, the program
should exit via sys.exit with an error message.
• Queries the API for the CoinDesk Bitcoin Price Index at
htps://api.coindesk.com/v1/bpi/currentprice.json, which returns a JSON object, among whose
nested keys is the current price of Bitcoin as a float. Be sure to catch any excep�ons, as with code
like:
import requests
try:
...
except requests.RequestException:
...
Outputs the current cost of n Bitcoins in USD to four decimal places, using” , “as a thousands
separator.
Hints