mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
chore(curriculum): add quotes around strings in Expense Tracker (#53520)
Co-authored-by: Dario-DC <dicillodario@gmail.com>
This commit is contained in:
+2
-2
@@ -10,10 +10,10 @@ dashedName: step-4
|
||||
A dictionary is another built-in data type in Python. A dictionary is a collection of data in the form of *key*-*value* pairs. Dictionaries are defined with curly braces `{}` and they contain key-value pairs separated by commas. Each key is followed by a colon `:` and the value:
|
||||
|
||||
```py
|
||||
{"amount": 50.0, "category": "Food"}
|
||||
{'amount': 50.0, 'category': 'Food'}
|
||||
```
|
||||
|
||||
In the example above, `amount` and `category` are keys, and `50.0` and `Food` are their the corresponding values.
|
||||
In the example above, `amount` and `category` are keys, and `50.0` and `'Food'` are their the corresponding values.
|
||||
|
||||
Create a dictionary with a key `amount` and value of the `amount` parameter and pass your new dictionary to the `.append()` call.
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-5
|
||||
|
||||
# --description--
|
||||
|
||||
Add another key-value pair to the dictionary you are appending to the `expense` list. Use the string `category` as the key, and the `category` parameter as the value.
|
||||
Add another key-value pair to the dictionary you are appending to the `expense` list. Use the string `'category'` as the key, and the `category` parameter as the value.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+3
-3
@@ -10,11 +10,11 @@ dashedName: step-9
|
||||
You can access values in a dictionary through its keys. You need to use the bracket notation and include the key between the square brackets:
|
||||
|
||||
```py
|
||||
my_dict = {"amount": 50.0, "category": "Food"}
|
||||
my_dict["amount"] # 50.0
|
||||
my_dict = {'amount': 50.0, 'category': 'Food'}
|
||||
my_dict['amount'] # 50.0
|
||||
```
|
||||
|
||||
You are currently interpolating the `expense` dictionary in your f-string. Modify the f-string expression to access the value of the `amount` key and the `category` key in the `expense` dictionary.
|
||||
You are currently interpolating the `expense` dictionary in your f-string. Modify the f-string expression to access the value of the `'amount'` key and the `'category'` key in the `expense` dictionary.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-16
|
||||
|
||||
# --description--
|
||||
|
||||
Within your `total_expenses` function, replace `pass` with a `lambda` function. Use `expense` as the parameter and return the value of the `amount` key in the `expense` dictionary.
|
||||
Within your `total_expenses` function, replace `pass` with a `lambda` function. Use `expense` as the parameter and return the value of the `'amount'` key in the `expense` dictionary.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-20
|
||||
|
||||
# --description--
|
||||
|
||||
Within the `filter_expenses_by_category` function, replace `pass` with a `lambda` function. Use `expense` as the parameter and return the comparison between the value of the `category` key of the `expense` dictionary and `category`.
|
||||
Within the `filter_expenses_by_category` function, replace `pass` with a `lambda` function. Use `expense` as the parameter and return the comparison between the value of the `'category'` key of the `expense` dictionary and `category`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ You should define a function named `main()` without parameters.
|
||||
})
|
||||
```
|
||||
|
||||
You should move the `expense` list inside the `main()` function body.
|
||||
You should move the `expenses` list inside the `main()` function body.
|
||||
|
||||
```js
|
||||
({ test: () => assert(__pyodide.runPython(`
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ while condition:
|
||||
<code>
|
||||
```
|
||||
|
||||
Below the `expense` list, create a `while` loop. Use `True` for the condition, and print the string `\nExpense Tracker` inside the loop body to show the title of the program.
|
||||
Below the `expenses` list, create a `while` loop. Use `True` for the condition, and print the string `'\nExpense Tracker'` inside the loop body to show the title of the program.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-25
|
||||
|
||||
The `while` loop you created in the previous step is an infinite loop that will allow the program to continuously present menu options until the user decides to exit.
|
||||
|
||||
After the `print()` call, add another one to print the string `1. Add an expense`.
|
||||
After the `print()` call, add another one to print the string `'1. Add an expense'`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-26
|
||||
|
||||
# --description--
|
||||
|
||||
Next, add another `print()` call and pass the string `2. List all expenses`.
|
||||
Next, add another `print()` call and pass the string `'2. List all expenses'`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-27
|
||||
|
||||
# --description--
|
||||
|
||||
Provide the other menu options by printing the following three strings in your `while` loop: `3. Show total expenses`, `4. Filter expenses by category`, and `5. Exit`.
|
||||
Provide the other menu options by printing the following three strings in your `while` loop: `'3. Show total expenses'`, `'4. Filter expenses by category'`, and `'5. Exit'`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-28
|
||||
|
||||
The `input()` function takes a user input and it returns the user input in the form of a string.
|
||||
|
||||
Inside your `while` loop, call the `input()` function passing the string `Enter your choice: ` as the argument, and assign the result to a variable named `choice`.
|
||||
Inside your `while` loop, call the `input()` function passing the string `'Enter your choice: '` as the argument, and assign the result to a variable named `choice`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ dashedName: step-29
|
||||
|
||||
# --description--
|
||||
|
||||
You are going to use conditional statements to check the user's choice. If the choice is `1`, it means the user wants to add an expense.
|
||||
You are going to use conditional statements to check the user's choice. If the choice is `'1'`, it means the user wants to add an expense.
|
||||
|
||||
Still in the `while` loop, under the `choice` variable, write an `if` statement to check if `choice` equals the string `1`. If it's true, it will be the starting point for adding a new expense.
|
||||
Still in the `while` loop, under the `choice` variable, write an `if` statement to check if `choice` equals the string `'1'`. If it's true, it will be the starting point for adding a new expense.
|
||||
|
||||
Inside the `if` statement body, declare a variable `amount` and assign it an empty `input()` call.
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-30
|
||||
|
||||
Inside the `if` statement, you should ask the user to enter the amount for the expense and store it in a variable.
|
||||
|
||||
Pass the string `Enter amount: ` to your empty `input()` call, so you can store the expense.
|
||||
Pass the string `'Enter amount: '` to your empty `input()` call, so you can store the expense.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-34
|
||||
|
||||
To list all expenses, you can use an `elif` statement after an `if` statement. The `elif` checks additional conditions and only works following an `if` statement.
|
||||
|
||||
Create an `elif` statement to check if the user's choice equals the string `2`. Inside the `elif` statement, print the string `\nAll Expenses:`.
|
||||
Create an `elif` statement to check if the user's choice equals the string `2`. Inside the `elif` statement, print the string `'\nAll Expenses:'`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-36
|
||||
|
||||
To show the total expenses, create an `elif` statement that checks if `choice == '3'`.
|
||||
|
||||
If it's true, it means the user wants to see the total expenses. So call `print()` and pass the string `\nTotal Expenses: ` as the first argument and `total_expenses(expenses)` as the second argument.
|
||||
If it's true, it means the user wants to see the total expenses. So call `print()` and pass the string `'\nTotal Expenses: '` as the first argument and `total_expenses(expenses)` as the second argument.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
+3
-3
@@ -7,9 +7,9 @@ dashedName: step-41
|
||||
|
||||
# --description--
|
||||
|
||||
To provide a way to exit the program, use another `elif` statement to check if `choice` equals the string `5`.
|
||||
To provide a way to exit the program, use another `elif` statement to check if `choice` equals the string `'5'`.
|
||||
|
||||
Inside the new `elif` statement, print the string `Exiting the program.` to show that the program is terminating its execution.
|
||||
Inside the new `elif` statement, print the string `'Exiting the program.'` to show that the program is terminating its execution.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -26,7 +26,7 @@ You should have `elif choice == '5':` in your code.
|
||||
})
|
||||
```
|
||||
|
||||
You should print `Exiting the program.` in your new `elif` statement.
|
||||
You should print `'Exiting the program.'` in your new `elif` statement.
|
||||
|
||||
```js
|
||||
({ test: () =>
|
||||
|
||||
Reference in New Issue
Block a user