Python Forum
My program subtracts fractions, but for some reason isn't simplifying them
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My program subtracts fractions, but for some reason isn't simplifying them
#5
(Feb-01-2018, 11:11 PM)Gribouillis Wrote: A definition inside a function's body, such as line 10 and 11 does not change the value of any variable named 'a' and 'b' outside the function's body.
So (a, b) in Line 6:
def fractionSubtraction(a, b):
synchronizes with (a, b) in Line 33:
fractionSubtraction(a, b)
So that 'a' and 'b' can be manipulated within the fractionSubtraction function's definition?

Even if that is the case, I still don't see why that's a smart way of doing things. How is that concept NOT ass-backwards? I thought the purpose of a main function was to call a bunch of other functions in order, so that you can manage the code of your program in an organized and object oriented fashion.

Please help me understand. Why is it such a good and wonderful thing that you're always forced to declare and initialize your variables in the main function instead of declaring and initializing them within the fractionSubtraction function definition that is responsible for manipulating their values in the first place anyway? I mean, doesn't declaring and initializing 'a' and 'b' in the main function definition make them global? Whatever happened to the concept of avoiding global variables whenever possible because of scope issues?
Reply


Messages In This Thread
RE: My program subtracts fractions, but for some reason isn't simplifying them - by RedSkeleton007 - Feb-02-2018, 07:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  coma separator is printed on a new line for some reason tester_V 4 581 Feb-02-2024, 06:06 PM
Last Post: tester_V
  Reason of the output himanshub7 2 2,220 Apr-28-2020, 10:44 AM
Last Post: TomToad
  Code used to work, not anymore for no apparent reason? chicagoxjl 1 1,930 Jan-08-2020, 05:05 PM
Last Post: jefsummers
  comparing integers and fractions tantony 3 2,052 Oct-02-2019, 04:32 PM
Last Post: tantony
  Help for simplifying code mmk1995 8 4,281 Sep-24-2019, 02:04 PM
Last Post: perfringo
  simplifying a stack of elifs Skaperen 8 4,197 Aug-17-2019, 04:13 AM
Last Post: Skaperen
  Syntax error for a reason I don't understand DanielCook 2 2,471 Aug-07-2019, 11:49 AM
Last Post: buran
  Simplifying my code ilondire05 5 3,832 Jul-21-2019, 03:21 AM
Last Post: scidam
  "invalid syntax" for no apparent reason wardancer84 2 7,214 Oct-03-2018, 11:57 AM
Last Post: wardancer84
  for some reason this isnt working lokchi2017 3 2,746 Aug-06-2018, 12:24 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020