3 Replies - 795 Views - Last Post: 19 March 2010 - 11:21 AM Rate Topic: -----

#1 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

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.

This post has been edited by baavgai: 19 March 2010 - 09:22 AM
Reason for edit:: Baavgai was an idiot and edited your post

Is This A Good Question/Topic? 0
  • +

Replies To: Global variable problem

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

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:
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.
Was This Post Helpful? 1
  • +
  • -

#3 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5826
  • View blog
  • Posts: 12,681
  • Joined: 16-October 07

Re: Global variable problem

Posted 19 March 2010 - 09:23 AM

Well, there's already a boolean in Python.

Perhaps something like:
def isOdd(n):
   return n%2 == 1

def showOdd(n):
   print {True: "Odd", False: "Even"}[isOdd(n)]

showOdd(4)
showOdd(5)


Was This Post Helpful? 1
  • +
  • -

#4 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1