#๐ Need help on fixing my code asap
73 messages ยท Page 1 of 1 (latest)
@mossy obsidian
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.
??
contribution_value = float(input('Enter your FSA contribution for the year as a whole number (max allowed is 3200): '))
expenditure_value = float(input('Enter your FSA expenditure for the year as a whole number (max allowed is 3200): '))
difference = contribution_value - expenditure_value
while contribution_value and expenditure_value != 0:
if difference < 0:
print(f'The difference is {difference}')
elif difference > 0:
difference * -1
print(f'{difference}')
elif difference == 0:
print(f'difference is same')
print(f'{contribution_value} and {expenditure_value}')
Hey @mossy obsidian!
It looks like you incorrectly specified a language for your 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!')```
You can **edit your original message** to correct your code block.
what's the issue ?
contribution_value = float(input('Enter your FSA contribution for the year as a whole number (max allowed is 3200): '))
expenditure_value = float(input('Enter your FSA expenditure for the year as a whole number (max allowed is 3200): '))
difference = contribution_value - expenditure_value
while contribution_value and expenditure_value != 0:
if difference < 0:
print(f'The difference is {difference}')
elif difference > 0:
difference * -1
print(f'{difference}')
elif difference == 0:
print(f'difference is same')
Ok so
When checking if something is equal to one thing or another, you might think that this is possible:
# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
print("That's a weird favorite fruit to have.")
While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.
So, if you want to check if something is equal to one thing or another, there are two common ways:
# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
print("That's a weird favorite fruit to have.")
# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
print("That's a weird favorite fruit to have.")
wait
I am trying to have it repeatedly ask the contrbution value until the user inputs 0
I want it to repeat until user inputs 0
ok
contrbution value and expenditure value
and I also need it to display the total number of inputs for expenditure
im so confused ngl
ok
heres an example
Enter your FSA contribution for the year as a whole number (max allowed is 3200): 1000
Enter the FSA expenditure as a whole number (enter 0 to finish): 100
Enter the FSA expenditure as a whole number (enter 0 to finish): 300
Enter the FSA expenditure as a whole number (enter 0 to finish): 400
Enter the FSA expenditure as a whole number (enter 0 to finish): 200
Enter the FSA expenditure as a whole number (enter 0 to finish): 0
You have a count of 4 FSA expenditures for the year.
You have accumulated a total of $1000 for the year.
Your expenditure total is the same as your FSA contribution.
alright
def ask_for_inputs():
cont = int(input("Enter your FSA contribution for the year as a whole number (max allowed is 3200): "))
expen = int(input("Enter your FSA expenditure as a whole number (enter 0 to finish): "))
return [cont, expen]
initial_cont = 1
initial_expen = 1
vals = []
while initial_cont != 0 and initial_expen != 0:
inputs = ask_for_inputs()
initial_cont = inputs[0]
initial_expen = inputs[1]
vals.append(initial_expen)
x = 0
for values in vals:
x += values
print(f"You have a count of {len(vals)} expenditures of the year.")
print(f"You have accumulated a total of ${x} for the year")
Hey @hushed saffron!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
def ask_for_inputs():
cont = int(input("Enter your FSA contribution for the year as a whole number (max allowed is 3200): "))
expen = int(input("Enter your FSA expenditure as a whole number (enter 0 to finish): "))
return [cont, expen]
initial_cont = 1
initial_expen = 1
vals = []
while initial_cont != 0 and initial_expen != 0:
inputs = ask_for_inputs()
initial_cont = inputs[0]
initial_expen = inputs[1]
vals.append(initial_expen)
x = 0
for values in vals:
x += values
print(f"You have a count of {len(vals)} expenditures of the year.")
print(f"You have accumulated a total of ${x} for the year")
Rather than complete OP's task for them please consider teaching.
Be aware OP has >1 channels open atm asking for assistance on different exercises.
sure i will tell him the logic
Running this code it does not repeat the question
rather it takes the input and prompts the user with the other question
read it again
I see now
How would I be able to change the output to be
Your expenditure total is $1000 under your FSA contribution for the year
if its under
Your expenditure total is $1000 overt your FSA contribution for the year
and same
now please learn the logic and try to build a diagram in your head
Step 1: Create a function to take input, making it function would help us to avoid repetition of code.
Step 2: Define initial non-zero values to execute the loop
Step 3: Define a list outside the loop to keep a track of total contribution and the total amount.
Step 4: Once loop is over get the length to get the number of contributions
Step 5: iterate over the list and add the values and print appropriate statements.
@mossy obsidian is this your code as you stated?
it has the necessary components to do what you are now asking for.
how do you say in it mathematics
Yes that is the code
It doesnt do it right tho
I asked if it was your code.
Because if so, then you already have the required knowledge to do what you are now asking.
If you don't, please make some attempt and let us know where you are going wrong so that you can be assisted in a way other than just producing code for you. We aren't here for that.
when I enter my codce
@ruby badge Be aware OP has >1 channels open atm asking for assistance on different exercises. i didn't get it
My suspicion is OP isn't doing this work - they're using our server to get exercises completed with little effort.
Our code of conduct pretty well covers how to ask questions, how to help, etc. And it's just generally bad form.
got it, noted
If I'm wrong I'm happy to apologise - but let's see some back and forth so that OP can be shown and helped in a way that is beneficial.
im just trying to get help its not like I havent been trying for the last 2 hours ๐ญ
I will keep that in mind, thanks
try use pen and paper before writing code, make a diagram
@mossy obsidian please show the code you're attempting as well as the traceback.
vals.append(initial_expen)
What does that do in the program?
Im just curious
Same with
x = 0
for values in vals:
x += values
the rest I understand pretty well
basically setting this value to a non-zero int which helps start the loop
the x is the total amount of expenditure
so we take each value from the loop and add it to x (total)
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.