Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRyan McGuire
3,758 PointsDid I use the wrong arguments or is there something wrong with my return line 8
Did I use the wrong arguments or is there something wrong with my return line 8
import re
def first_number(numbers):
return re.search(r'\d',numbers)
def numbers(count,string):
return re.search(r'"\w"*count',string)
2 Answers
Steven Parker
231,268 PointsYou need to remove the extra set of quotes that enclose the word "count" for it to be recognized as a variable name. Also, since the function should be looking for numbers, you'll want to use "\d" instead of "\w" for the character class.
You could also create a recurrence constraint by adding a value and perhaps a comma between curly braces ({}
). And for that method you may want to build up the regex string using formatting or concatenation.
kgoldthorpe
7,802 PointsYou don't need the extra ' ' around "\w"*count and the \w is still a \d like from the first challenge.
a passing example below:
import re
def first_number(string_argument): return re.search(r"\d", string_argument)
def numbers(count_int, count_str): return re.search(r"\d" * count_int, count_str)