Computer Science Canada Problems with a Question |
Author: | Sniper4Life [ Mon Apr 13, 2009 5:34 pm ] |
Post subject: | Problems with a Question |
Hey I've been having problems with a certain question and the language which I need to do it in is Python. This is the question: Write a program that reads in a file name from the user and tells them what kind of file it is by looking at the extension. Your program must be able to recognize at least 5 different file types. e.g. "Dogs.doc" is a Word Document So how would I do this? I don't understand how to do this because in order to do it you need to basically split the input right? And then perform the operations? I just don't get how to do that. Like...this question has more to do with strings than integers...so its a bit confusing for me...would someone like to clarify for me? |
Author: | Insectoid [ Mon Apr 13, 2009 5:41 pm ] |
Post subject: | RE:Problems with a Question |
there was another thread with this exact question somewhere.... here: http://compsci.ca/v3/viewtopic.php?t=20527 |
Author: | BigBear [ Mon Apr 13, 2009 5:42 pm ] |
Post subject: | RE:Problems with a Question |
try looking up help(str) in the shell to see what commands are availible |
Author: | Tony [ Mon Apr 13, 2009 5:46 pm ] |
Post subject: | RE:Problems with a Question |
pattern matching actually. You are right, it's operations on strings. Given a string, you are asked to find a substring that follows the last dot. Matching the string extension to the full name of a program is just aesthetics. Keep in mind that I could enter something like "dogs.documents.jpeg" for a file name. |
Author: | Insectoid [ Mon Apr 13, 2009 5:47 pm ] |
Post subject: | RE:Problems with a Question |
I would search the string backwards, each time adding that letter to the front of the string and stopping when you hit a ".". |
Author: | Sniper4Life [ Mon Apr 13, 2009 6:22 pm ] |
Post subject: | RE:Problems with a Question |
Could someone actually WRITE the answer to this? I learn welly from actually reading code and trying to understand it. The question is from McKenzie's exercises...so ya. If I could see what the answer to THIS would be, I could learn from it and use it for all his other questions. |
Author: | Tony [ Mon Apr 13, 2009 6:40 pm ] |
Post subject: | RE:Problems with a Question |
Not quite. My solution would open up a can of warms that are regular expressions http://www.google.ca/search?hl=en&q=site%3Acompsci.ca/v3%20intitle%3Aregex-tut&meta= |
Author: | Sniper4Life [ Mon Apr 13, 2009 6:47 pm ] |
Post subject: | RE:Problems with a Question |
darn it...i cant figure it out...like i nvr learned bout strings manipulation or like anything about strings in python...and every time i search it up on google i dont find any relevant information that could help me >< |