Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problems with a Question
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Sniper4Life




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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
BigBear




PostPosted: 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
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: 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 ".".
Sniper4Life




PostPosted: 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.
Tony




PostPosted: 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=
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sniper4Life




PostPosted: 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 ><
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: