We help IT Professionals succeed at work.

Python3 Question

sara2000
sara2000 asked
on
How would you code for this problem?

Define the function check(s). The function returns 1 when string 's' contains at least one digit and returns 0 otherwise.
Comment
Watch Question

Software Engineer
Distinguished Expert 2018
Commented:

This can be an example....

 def check(s):
   for digit in "0123456789":
      if digit in s:
         return 1
   return 0
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:

Another way...


def check(s):
  for char in s:
    if char in '0123456789':
      return 1
  return 0


NorieAnalyst Assistant

Commented:

And another...

def check(strcheck): 
    if any(char.isdigit() for char in strcheck): 
        return 1 
    else: 
        return 0