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 trialAli Amirazizi
16,087 PointsWhat do does (kind = "string" and kind == "number") mean?
I don't understand how these statements work. Is the word "kind" a keyword? Also how does putting the word "number" in quotes check to see if it's an integer thats being passed, since its in string quotes.
Ali Amirazizi
16,087 PointsI think I figured it out. The function works to change the users string input into a number(if they enter a number) because anything inputed is evaluated as a string. Thereby, if a number is inputed, it is originally a stringy number which then changed and evaluated as a number.
4 Answers
Roberto Alicata
Courses Plus Student 39,959 Pointsin the first line
def ask(question, kind="string")
kind="string" means that the function accepts an optional parameter named kind so if you don't specify it, it gets the value of "string".
for example:
ask("Are you ok?")
it is converted internally into
ask("Are you ok?", "string")
if you write instead this:
ask("Tell me your lucky number","int")
kind parameter will be = "int"
Thas Eagans
Courses Plus Student 2,533 PointsI'm no Ruby coder, but if its like any of the other languages I've worked with:
kind = "string" assigns "string" to the variable kind. kind == "number" checks the variable kind to see if its value is equal to "number".
</TREagans>
Jitli Gan
2,668 PointsCan someone explain again? I don't quite understand this.
Shaimoom Newaz
7,219 PointsTry adding the string "number" to the function in your workspace:
answer = ask("What is your name?", "number")
the code will now return integers. even if you enter a string, it will return a value of zero.
abdo esam
Courses Plus Student 292 Pointsi add int values and returned to 0 but when i leave it into string it works well!
Ali Amirazizi
16,087 PointsAli Amirazizi
16,087 PointsHi, thanks for your response. I'm slowly wrapping my head around the logic. Here's the code snippet for context.