#🔒 code help

95 messages · Page 1 of 1 (latest)

mellow echoBOT
#

@bitter cairn

Python help channel opened

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.

bitter cairn
#

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!")```
placid tide
bitter cairn
mellow echoBOT
#

Hey @ancient glacier!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
ancient glacier
#

    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

#

👍

bitter cairn
bitter cairn
#

?

dusty vigil
#

that means

#

subtract

obtuse yacht
#
budget -= expense

Is the same as

budget = budget - expense
ancient glacier
#

It’s takes away budget from expenses each iteration,

#

Meaning every time it goes through a loop.

ancient glacier
#

It’s updating the budget.

bitter cairn
#

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”)```
ancient glacier
bitter cairn
#

what does indentation mean?

ancient glacier
#

Must be on the same indent lines as your if and exif statements

ancient glacier
bitter cairn
#

oh

ancient glacier
#

It’s called white space

bitter cairn
#

yeah ill fix that

#

can i assk you

#

what does [] mean ik its a list but

#

why do i have to put it?

ancient glacier
#

Yes you need to define the list

bitter cairn
#

okay and for option 4 since its true statement how do i stop it

ancient glacier
#

It’s giving you an error because it has no associated vereable

bitter cairn
#

because it will keep running forever right?

ancient glacier
#

Use the break function

bitter cairn
bitter cairn
ancient glacier
#
expenses = []```
#

You can add the break function at the end of the condition because python reads line by line

bitter cairn
#

can it be budget instead of expenses?

ancient glacier
#

    elif option == 4:
        print("Goodbye!")
        break
bitter cairn
#

ohhh

#

okay

#

Tysmmmmmmm

#

is my code correct?

#

Like to this correct

ancient glacier
bitter cairn
#
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.")```
mellow echoBOT
#

Hey @bitter cairn!

Please edit your message to use a code block

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!')```
ancient glacier
#

That should be correct

bitter cairn
#

thank u so muchhhhhhhhhh

ancient glacier
#

No problem bro

bitter cairn
#

I have a question

#

What does

#

< this mean

bitter cairn
ancient glacier
#

That is less than

ancient glacier
#

Greater than 1

bitter cairn
#

Yeah

#

How do i put it

ancient glacier
#

You can check if budget is greater than 1 with if statements

bitter cairn
#

Do i put it in the option?

ancient glacier
#

Do you want to check if it’s greater then 1

bitter cairn
#

Option = int(input(“choose an option number: >”

bitter cairn
#

What does it mean

#

The >

ancient glacier
#

Oh

#

Mmhm

bitter cairn
#

yes >1 and >2

ancient glacier
#

That’s weird ?

bitter cairn
#

its oky

#

Thank u sm ill fighre it out

#

Thank uuu

ancient glacier
#

Dude what dose it mean

bitter cairn
#

im not sure

ancient glacier
#

No problem, it was nice helping

bitter cairn
#

thank u

ancient glacier
#

They aren’t relevant.

hybrid coral
#

Wherever there's a >, the program prompted the user for input. The number immediately following it is the user's response.

mellow echoBOT
#
Python help channel closed for inactivity

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.