#๐ Pricing System
66 messages ยท Page 1 of 1 (latest)
@full tinsel
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.
I'm new to python and I'm having problems with my functions calling at the wrong time and in the wrong order. It's a simple calculator with functions and if else statements. I know there's multiple ways around it but it hasn't clicked yet. displayChoice() and main() both call the same 3 functions. I'm not sure if its a problem with calling the display function in main since they're being used as well as assigned in main or something similar. If you need more context or the rest of the code feel free to dm. I'm sure it's simple but thanks for the help!
(forgot to add the attachment oops)
it's not an issue to call the function in two places, but it depends on what is your final goal
but I don't see what you are trying to do here
so you need to explain what you are trying to do and show us the rest of the functions
Its a calculator to determine the price for an item in this case a pc with different components and varying prices
okay so one issue I see
the following functions: [selectStorage, selectGpu, selectRAM] are suppose to return values
you try to ask the user to select which one he wants to call inside displayChoice
hey
yet you are not storing what he write
but then once again you do it inside the main function
so why is that?
it would be better if you paste your whole code here instead of sending screenshots
lol
bruh
i can't paste the whole things without hitting the character limit hold on
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
yeah it works, but there is an issue with your function calls the options twice when you buy stuff
if display == "S":
selectStorage()
if display == "G":
selectGpu()
if display == "R":
selectRAM()
``` this part makes you call for the function, but in the main function, you called the functions again, which made everything repeat twice.
```py
def main():
# sets base price and calls functions
displayChoice() #the function shown above^^^
basePrice = 400
storageChoice = selectStorage()
gpuChoice = selectGpu()
ramChoice = selectRAM()
calcCostandDisplay(basePrice, storageChoice, gpuChoice, ramChoice)
I see
I want that function to only choose which option. Lets say "S" and then display options for storage which the user can then choose. Calling them in main was supposed to assign them to 'storageChoice' which is sent along with the others as seen to calculate and display.
Yeah they are assigned the result of the function, which they later get sent into the calcCostandDisplay function for calculation
for the multiple if statement part, it doesn't matter if they exist or not, as the only purpose is to call the function
for example, storageChoice = selectStorage()
the result of selectStorage() function is automatically saved in storageChoice
also, ```py
totalCost = (basePrice + storPrice + gpuPrice + ramPrice)
print("The cost of your custom PC is: ")
print("Storage", storPrice)
print("GPU: ", gpuPrice)
print("RAM:", ramChoice)
print("Total:", totalCost)
main()
you did `print("RAM:", ramChoice)` instead of ramPrice lol
oh wait i forgot to ask what's the problem you have
Mainly I'm getting issues with the displayChoice function
It worked as intended itself but moved on and repeated the same, instead of asking for the next part. then calculating and displaying
like this?
yes.
yeah this is what I was talking about, it calls the function twice, once in displayChoice and once in main function
I want to ask for which option, (H, O, F) store the option and move on to the next part. I'm not sure how to not call it twice if I'm clarifying which part, and also assigning to the choice they made.
for the displayChoice function, do you want all of those functions to be shown?
well when you called the function, for example the select storage function, it has a input to ask you which option to pick
then you have a if statement that checks if the option is not valid, else, return the option
this return custChoice saves the option
so is the displayChoice function redundant?
!e
def equation(operator,number):
total = 0
if operator == "+":
total += number
return total
answer = equation("+",6)
print(answer)
@visual fulcrum :white_check_mark: Your 3.12 eval job has completed with return code 0.
6
I would say its purpose is to only to show the menu, or you would have to make it more steps
like removing the functions in the main function
then calling all 3 functions on all 3 if statements
if option == "S":
storChoice = selectStorage()
GPUChoice = selectGPU
RAMChoice = selectRAM
elif option == "G"
selectGPU
selectStorage
selectRAM
prob something like that
this is what i meant by the saving of the option of the function
so if they choose "S" for example. I could call the function as well as assign their choice to the argument I send to calculate? instead of calling it in main also
well if the calculation function is in the main function, it won't receive the variables inside the displayChoice function
you would have to include the calculation function in displayChoice function
I was abt to ask that. ok i see
well my suggestion is to remove the if statements in the displayChoice function and just continue the functions in the main loop
everything will function ok
I need a separate function for displaying, calculating costs, and selecting choices
I assigned the choice to the function if the input for display is correct for each function under each if statement. put the calcCost function in the display function, and sent base price as an argument so the casing check function works as well. thanks for the help!
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.
๐ Pricing System