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 trialmichaelangelo owildeberry
18,173 PointsWrite a function named first_number that takes a string as an argument. The function should search, with a regular expre
Write a function named first_number that takes a string as an argument. The function should search, with a regular expression, the first number in the string and return the match object.
syntax error, please help =)
import re
def first_number("rock3"):
re.search(r'\d')
return str(first_number)
3 Answers
William Li
Courses Plus Student 26,868 PointsHey, Michaelangelo, couple problems here
- when defining a function, you shouldn't manually pass in an actual string as function parameter.
-
re.search
takes a second argument.
def first_number(s):
return re.search(r'\d', s)
Ryan Hartigan
3,426 PointsThis is my first time going through Python. Nowhere in the Track up to this point have they mentioned a "def" function or how to define function parameters - the idea that there isn't a "Show Answer" button when the student has not been given enough information to solve the problem properly, is mind-boggling.
Aghogho Okajevo
1,029 PointsHello Ryan,
I presume you took the Django Track, This track is taught with an assumption that you've covered Python Basics Course already.
Cheryl Hughey
9,034 PointsI agree. Since Treehouse has moved to teaching User Experience, I really think they need to revisit their decision not to use a "Show Answer" feature. Assuming a student has taken and understood a previous course doesn't help the buy-in for retainment.
Devin Hight
3,141 PointsThere is a lot of that. You'll see stuff in the solution for most of these that they have never gone over before. To be fair, it doesn't seem like just a Treehouse problem.
Michael Cripps
4,432 PointsYou are right my friend. There really was no build up to this.
Denis Watida Machaka
7,311 Pointsimport re def first_number(denis): return re.search(r'\d',denis)