This post has been edited by baavgai: 19 March 2010 - 09:22 AM
Reason for edit:: Baavgai was an idiot and edited your post
Global variable problem
Page 1 of 13 Replies - 668 Views - Last Post: 19 March 2010 - 11:21 AM
#1
Global variable problem
Posted 19 March 2010 - 08:08 AM
Original post lost due to Baavgai. If OP could undo my stupid, I'd appreciate it.
Replies To: Global variable problem
#2
Re: Global variable problem
Posted 19 March 2010 - 09:16 AM
I don't know whether I'd call this "wrong" or not, but you can trim down your code by just returning the actual boolean:
If you're attached to the way you're writing things now though, I think the issue is that you've defined your constants within your main() function - try moving them outside the function definition.
def is_odd(number): return number % 2 == 0
If you're attached to the way you're writing things now though, I think the issue is that you've defined your constants within your main() function - try moving them outside the function definition.
#3
Re: Global variable problem
Posted 19 March 2010 - 09:23 AM
Well, there's already a boolean in Python.
Perhaps something like:
Perhaps something like:
def isOdd(n):
return n%2 == 1
def showOdd(n):
print {True: "Odd", False: "Even"}[isOdd(n)]
showOdd(4)
showOdd(5)
#4
Re: Global variable problem
Posted 19 March 2010 - 11:21 AM
Thank you both baavgai and girasquid, I tried out both methods and they work fine, but just for the sake of laziness im gonna just put my global variables out of main function.
Thanks again!
Thanks again!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|