0

I wrote a code and the only problem I have is the assert function syntax. For the function great(s,b), b has to be in range (2,37) and s has to be a string. At the same time I need to assert that s contain only digits 0-9, letters a-z, and the . (dot).

def great(s,b):
       assert b in range(2,37) and type(s)==str
alko
  • 46,136
  • 12
  • 94
  • 102
user2751595
  • 337
  • 3
  • 13

2 Answers2

0

To check whether b is integer in range from 2 to 37 inclusively:

assert isinstance(b, int) and 2 <= b <= 37

s being a string (for python 3)

assert isinstance(s, str)

For checking against fixed number of symbols, one can use regular expression:

import re
allowed_re = re.compile('^[0-9a-z.]*$')
assert allowed_re.match(s) 
Community
  • 1
  • 1
alko
  • 46,136
  • 12
  • 94
  • 102
-1

the error info needed, assertion link, http://www.tutorialspoint.com/python/assertions_in_python.htm

def great(s,b):
        assert ((b in range(2,37)) and (type(s)==str)), "error happens"
JQian
  • 226
  • 2
  • 9