+ 1

Making Functions more simple ?

https://code.sololearn.com/cA3A12a20A3a here is my code It reads from a txt file to display menu and when purchases are made it subtracts inventory and overwrites the text file then loops back to the main Im getting a Code smell error because I know that I should make it more simple but I'm not sure what the best way would be to split the big function to where it all comes together Anybody have any advice on how to make this code shorter? keep in mind that this is for an assignment and the instructions specifically want the code to use an exterior text file so that is why I have to read it and strip it and all that my goal is to achieve the same functionality with a shorter code or at least splitting that large function into two

19th Mar 2021, 11:30 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
8 Respostas
+ 1
Coder Kitten great response thanks so much im a noob but i want to learn these things and the way they should be done can you give and example of the outermost structure that you would use for example the code i have posted is something like def main() while True fun1() fun2() fun3() main() def fun1 def fun2 def fun3 main()
20th Mar 2021, 2:49 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
Coder Kitten oh awesome let me look and learn all that i can thats so helpful! Weve learned the basics but only with minimal examples so its been a challenge trying to write the programs in the assignments and trying to maintain zen at the same time! and our instructor never shows us her code at the end so we never see a career programmers way that they would achieve it if that makes sense thats why im reaching out here. thank you for your help im already seeing things in your code that are answering questions that i had... like i knew that global vars should not be used but then i was confused about how to pass vars between functions or use parameters or even a what a solid program should look like for something long like this without digging deep into the stack like you said.. so much to learn and so little time! haha
20th Mar 2021, 3:06 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
Coder Kitten oh perfect thank you so much ! yeah we havent got to OOP yet but i think we will soon were on our second month of the semester before that i had no experience with programming so this is all very helpful
20th Mar 2021, 3:25 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
Coder Kitten here was the original assignment if you wanted to see how the text file looked and i realized i forget the exception if the file isnt found haha:p
20th Mar 2021, 4:59 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
https://imgur.com/gallery/CPmIVAc Coder Kitten oops i forgot to linke it hahaha
20th Mar 2021, 8:47 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar