5.1 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 5e44413e903586ffb414c94e | App per il budget | 10 | 462361 | budget-app |
--description--
Lavorerai a questo progetto con il nostro codice d'inizio su Replit.
- Start by importing the project on Replit.
- Next, you will see a
.replitwindow. - Select
Use run commandand click theDonebutton.
--instructions--
Completa la classe Category in budget.py. Dovrebbe essere in grado di instanziare oggetti basati su diverse categorie di budget, come food, clothing, e entertainment. Quando gli oggetti sono creati, ricevono come argomento il nome della categoria. La classe dovrebbe avere una classe di istanza chiamata ledger che è una lista. La classe dovrebbe anche contenere i seguenti metodi:
- A
depositmethod that accepts an amount and description. If no description is given, it should default to an empty string. The method should append an object to the ledger list in the form of{"amount": amount, "description": description}. - A
withdrawmethod that is similar to thedepositmethod, but the amount passed in should be stored in the ledger as a negative number. If there are not enough funds, nothing should be added to the ledger. This method should returnTrueif the withdrawal took place, andFalseotherwise. - A
get_balancemethod that returns the current balance of the budget category based on the deposits and withdrawals that have occurred. - A
transfermethod that accepts an amount and another budget category as arguments. The method should add a withdrawal with the amount and the description "Transfer to [Destination Budget Category]". The method should then add a deposit to the other budget category with the amount and the description "Transfer from [Source Budget Category]". If there are not enough funds, nothing should be added to either ledgers. This method should returnTrueif the transfer took place, andFalseotherwise. - A
check_fundsmethod that accepts an amount as an argument. It returnsFalseif the amount is greater than the balance of the budget category and returnsTrueotherwise. This method should be used by both thewithdrawmethod andtransfermethod.
Quando l'oggetto budget è stampato dovrebbe mostrare:
- A title line of 30 characters where the name of the category is centered in a line of
*characters. - A list of the items in the ledger. Each line should show the description and amount. The first 23 characters of the description should be displayed, then the amount. The amount should be right aligned, contain two decimal places, and display a maximum of 7 characters.
- A line displaying the category total.
Ecco un esempio dell'output:
*************Food*************
initial deposit 1000.00
groceries -10.15
restaurant and more foo -15.89
Transfer to Clothing -50.00
Total: 923.96
Oltre la classe Category, crea una funzione, al di fuori della classe, chiamata create_spend_chart che prende una lista di categorie come argomento. Dovrebbe restituire una stringa che è un grafico a barre.
Il grafico dovrebbe mostrare la percentuale spesa in ogni categoria passata alla funzione. La percentuale spesa dovrebbe essere calcolata solo con i prelievi e non i depositi. Lungo il lato sinistro del grafico dovrebbero esserci etichette 0 - 100. Le barre nel grafico dovrebbero essere fatte di caratteri "o". L'altezza di ogni barra dovrebbe essere arrotondata per difetto alla decina più vicina. La linea orizzontale sotto le barre dovrebbe finire due caratteri dopo l'ultima barra. Ogni nome di categoria dovrebbe essere scritto verticalmente sotto la barra. Dovrebbe esserci un titolo in cima che dice "Percentage spent by category".
Questa funzione sarà testata con al massimo quattro categorie.
Guarda all'esempio di output qui sotto con attenzione e assicurati che gli spazi dell'output combacino esattamente con l'esempio.
Percentage spent by category
100|
90|
80|
70|
60| o
50| o
40| o
30| o
20| o o
10| o o o
0| o o o
----------
F C A
o l u
o o t
d t o
h
i
n
g
I test unitari per questo progetto sono in test_module.py.
Sviluppo
Scrivi il tuo codice in budget.py. Per lo sviluppo, puoi usare main.py per testare la tua funzione Category. Usa il bottone "run" e main.py sarà eseguito.
Testare
Abbiamo importato i test da test_module.py in main.py per tua convenienza. I test saranno eseguiti automaticamente quando usi il bottone "run".
Consegnare
Copia l'URL del tuo progetto e consegnalo nell'input qua sotto.
--hints--
Dovrebbe creare una classe Category e superare tutti i test.
--solutions--
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/