#🔒 code help
95 messages · Page 1 of 1 (latest)
@bitter cairn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
If anyone could help
budget = float(input("Enter your monthly budget:"))
while True:
print("Choose an option:")
print("1. add an expense:")
print("2. view expenses:")
print("3. view remaining budget:")
print("4. exit:")
option = int(input("choose an option number:"))
if choice == 1:
elif choice == 2:
print("expenses:", expenses)
elif choice == 3:
print("remaining budget:" budget)
elif choice == 4
print("goodbye!")```
there's no body for the choice being 1?
Yea im stuck here
I could help…
Hey @ancient glacier!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
if option == 1:
expense = float(input("Enter expense amount: "))
expenses.append(expense)
budget -= expense
print("Expense added.")
Asks for expense amount and append the user outputs to expenses.
It takes the budget away from expense each time it loops
👍
thank u so much
Why did u do the -=
?
budget -= expense
Is the same as
budget = budget - expense
That’s cool. You could use that if you want.
It’s takes away budget from expenses each iteration,
Meaning every time it goes through a loop.
You want to do that for choice 1 right?
It’s updating the budget.
ohh okay
can u check if its correct
my code ?
budget = float(input("Enter your monthly budget:"))
while True:
print("Choose an option:")
print("1. add an expense:")
print("2. view expenses:")
print("3. view remaining budget:")
print("4. exit:")
option = int(input("choose an option number:"))
if option == 1:
expense = float(input("Enter expense amount: "))
expenses.append(expense)
budget -= expense
print("Expense added.")
elif option == 2:
print("expenses:", expenses)
elif option == 3:
print("remaining budget:" budget)
elif option == 4:
print("goodbye!")
else:
print(“please enter a valid number”)```
Else has wrong indentation it looks like
what does indentation mean?
Must be on the same indent lines as your if and exif statements
It’s when it creates spaces
oh
It’s called white space
yeah ill fix that
can i assk you
what does [] mean ik its a list but
why do i have to put it?
Yes you need to define the list
okay and for option 4 since its true statement how do i stop it
It’s giving you an error because it has no associated vereable
because it will keep running forever right?
Use the break function
Do i add it in the start
where in 4?
expenses = []```
You can add the break function at the end of the condition because python reads line by line
can it be budget instead of expenses?
on else or the last elif
elif option == 4:
print("Goodbye!")
break
Yes
budget = float(input("enter your monthly budget: "))
expenses = []
while True:
print("choose an option:")
print("1. add an expense")
print("2. view expenses")
print("3. view remaining budget")
print("4. exit")
option = int(input("choose an option number: "))
if option == 1:
expense = float(input("enter expense amount: "))
expenses.append(expense)
budget -= expense
print("expense added.")
elif option == 2:
print("expenses:", expenses)
elif option == 3:
print("remaining budget:", budget)
elif option == 4:
print("goodbye!")
break
else:
print("please enter a valid number.")```
Hey @bitter cairn!
Make sure you put your code on a new line following py. There must not be any spaces after py.
Here is an example of how it should look:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
Yes
That should be correct
thank u so muchhhhhhhhhh
No problem bro
The picture here ‘> 1’
That is less than
You can check if budget is greater than 1 with if statements
Do i put it in the option?
Do you want to check if it’s greater then 1
Option = int(input(“choose an option number: >”
No wait
What does it mean
The >
yes >1 and >2
That’s weird ?
Dude what dose it mean
im not sure
No problem, it was nice helping
thank u
the ">" represent the prompts
Wherever there's a >, the program prompted the user for input. The number immediately following it is the user's response.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.