![]() |
I have no clue what I am doing wrong here - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I have no clue what I am doing wrong here (/thread-37489.html) |
I have no clue what I am doing wrong here - elroberto - Jun-18-2022 Code Version 1: message="Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!" print(message) amount_of_cable=input("Please enter the desired amount of fiberoptic cable needed for your project: ") float(amount_of_cable)#I think I'm doing something wrong here if amount_of_cable<100: def multiply(amount_of_cable,b): result=int(amount_of_cable)*0.87 return result print(multiply(amount_of_cable,0.87))When Ran in Console: Code Version 2 (Attempted Solution):message="Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!" print(message) amount_of_cable=int(input("Please enter the desired amount of fiberoptic cable needed for your project: ")) #I think I'm doing 5. something wrong here if amount_of_cable<100: def multiply(amount_of_cable,b): result=int(amount_of_cable)*0.87 return result print(multiply(amount_of_cable,0.87)) print(amount_of_cable,"Is this correct? Please say 'Yes, or No'") question=input("Please say Yes, or No: ") #Test this in Replit!!!When Ran in Console: No error message regarding the if statement, but it looks like it just skipped over it. What am I doing wrong? All I'm trying to do is get the number that is set to the amount_of_cable variable to be recognized as less than 100, and then multiply that same number by 0.87
RE: I have no clue what I am doing wrong here - ndc85430 - Jun-18-2022 Please format your code properly - put it within "[python]" tags, as that will add line numbering for you, preserve indentation and add syntax highlighting. As it is, it's really hard to read. RE: I have no clue what I am doing wrong here - rob101 - Jun-18-2022 First off, as already posted: please use the code tags
edit: in fact, as is, I can't see that you even need your custom function, but post back when you've made the changes and we'll take it from there. RE: I have no clue what I am doing wrong here - BashBedlam - Jun-18-2022 Try it like this: def multiply(amount_of_cable,b): result=int(amount_of_cable)*0.87 return result message="Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!" print(message) amount_of_cable=int(input("Please enter the desired amount of fiberoptic cable needed for your project: ")) #I think I'm doing 5. something wrong here if amount_of_cable<100: print(multiply(amount_of_cable,0.87)) print(amount_of_cable,"Is this correct? Please say 'Yes, or No'") question=input("Please say Yes, or No: ") #Test this in Replit!!! RE: I have no clue what I am doing wrong here - deanhystad - Jun-18-2022 While this is legal Python code: amount_of_cable = 100 if amount_of_cable < 100: def multiply(amount_of_cable,b): result=int(amount_of_cable)*0.87 return resultIt is very unusual code, and it does not do what you think it does. This defines a function: def multiply(amount_of_cable): return amount_of_cable * 0.87Now that the function is defined you can use it in your program. Like this: if amount_of_cable < 100: price = multiply(amount_of_cable):In your program the if statement controlled if the function was defined, not if it was used. If amount of cable >= 100 the function is not defined and it was not called. If the amount of cable < 100 the function was defined, but not used. Neither result are what you want. |