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 trialMikkel Bielefeldt
3,227 PointsIs there an int in the string?
So I've been searching around, and for some reason I haven't been able to find anything. I have found a lot of stuff that separates a lot of the code, but not like a full program. I need to find out, if there's ANY, int or float in the string.
name = input("What's your name? ")
for temp in name:
name_splitted = temp
print(name_splitted)
if any(name_splitted) is int:
print("That's not a valid name.")
else:
print("Alright then.")
Hope you can help.
1 Answer
Steven Parker
229,695 PointsIsn't this essentially the same as the question you asked 2 days ago?
You don't need the loop with "name_splitted", you can just incorporate that same test here:
if any(char.isdigit() for char in name):
Mikkel Bielefeldt
3,227 PointsMikkel Bielefeldt
3,227 PointsYeah I know, but I tried it and did some different kinds of it and I couldn't get it working. The code you posted above helped and works perfectly, but I got one question what does "char"? Thanks for the help.
Steven Parker
229,695 PointsSteven Parker
229,695 PointsThe term "char" represents any single character in the name.
If you translated that code into English, it would be "if any character in the name is a digit".