1 Replies - 370 Views - Last Post: 03 May 2011 - 02:58 AM Rate Topic: -----

#1 successfulangel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-May 11

how can i write my coding in Function method?

Posted 03 May 2011 - 12:59 AM

i want some idea to write my coding in Function style.and i also want to know how to use isdigit()function when i check my error.I hope i can get some clue to change my coding style.Thanks in advance.

Attached File(s)


Is This A Good Question/Topic? 0
  • +

Replies To: how can i write my coding in Function method?

#2 Eric115  Icon User is offline

  • coderさん
  • member icon

Reputation: 63
  • View blog
  • Posts: 696
  • Joined: 19-January 09

Re: how can i write my coding in Function method?

Posted 03 May 2011 - 02:58 AM

Ok, first of all using the isdigit() function should be fairly easy. The isdigit() just takes a string and tells you if all of the characters in the string are a number. It will return a bool. For example
>>> a = 'abc'
>>> b = '123'
>>> print a.isdigit()
>>> False
>>> print b.isdigit()
>>> True


As for using functions in your code, you could use a different function for each keyboard response. For example (this is you code just modified)
...
elif response=="V":
    scores = getscores()
    print scores
...
def getscores():
    scores = """"""
    f=open("score.txt",'r')
    for line in f:
        scores += line+'\n'
    return scores


That is a very simple example of how to put in a function with return.
I hope that is what you mean by 'function style'
Hope I could help
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1