Nov-01-2016, 07:17 AM
(Nov-01-2016, 04:29 AM)Larz60+ Wrote: For starters:
Your number1 code
number1 = raw_input("Choose a number.") def number1(): if number1 <= 1: number1 = "a" elif number1 > 1: number1 = number1Very confusing and potential for error exists (even though technically legal) when variables are named the same as functions
also you don't need the elif it does nothing.Why would you have to make a variable equal to itself?
You should also refrain from using globals, but that's something you will pick up with experience ... just keep it in the back of your mind.
In addition, if you're going to the trouble of naming something 'number'... don't store anything but numbers in that variable
finally, you never call this function, so why is it there? and even if you did, you never look for an 'a'
to execute a function, the syntax is functionname(arguments). I think you are confused about this.
defaults should only be used if they make sense, not as a standard way to call a function.
your final_product is a good example of BAD code.
Try fixing things up a bit, then come back with specific issues.
also, next time post the code here (unless it's mile long)
Actually within the body of the function it compares the function object with the number. If you add
print number1within the function body, it will print the function object, not the value of the global name number1
Also note that raw_input will return str, not int, so without conversion the global name number1 will hold str anyway.
It looks like function object is always greater than int object and the opposite when comparing with str object or when compare str object with int objects
def foo(): pass bar=10**100 bar2='some str' print foo print bar print bar2 print foo>bar print foo>bar2 print bar>bar2
Output:<function foo at 0x036470B0>
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
some str
True
False
False