python - My function isnt getting defined for some reason? -


i tried write function returns true if there integer in string. however, function apparently not defined. when try run code get

traceback (most recent call last):   file "<pyshell#10>", line 1, in <module>     integer(5) nameerror: name 'integer' not defined 

here code:

def integer(s): z = '' z = z + in s:     if s == int:         return true 

welcome python in case :)

in python white space , indentation essential. function needs indented correctly, so:

def integer(s):     z = ''     z = z +     in s:         if s == int:             return true 

now, function isn't quite doing want to. if s == int: isn't quite right syntax. you'd want more if s in "0123456789": because s string if it's between 0-9, , make sure @ end of function return false if function never found digit. so:

def integer(s):     in s:         if s in "0123456789":             return true     return false 

to make sure can define simple function, try doing hello world program can make sure definitions working right.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -