Coordinates Units Converter ---------------------------- Create a mock data file containing a list of coordinates in the format "ObjID RA(hms) Dec(dms)". Write a program to accept the name of the file as a command line argument and convert it into a file with a suitable new name and having the following format "ObjID RA(decimal degrees) Dec(decimal degrees). Remember: command line arguments were used in the last demo program in the second talk. Word Wrapper ------------ If a file is given which has arbitarily long lines. Can you write a program to word wrap the file to 80 characters? It would be lovely if the file name could be accepted as a command line argument. Further, the 80 character limit can also be accepted as a second OPTIONAL command line argument. You should use a text editor to create a file and test the program. Optional Extensions: Try and take care of splitted words towards end of each line. Devise a strategy to handle them. Column Addition ---------------- Make a mock file containing two columns, say apparent magnitude and distance modulus. Write a program to create another file which has these two columns and a third which is the absolute magnitude. The tiresome amount of coding you will do should hopefully make you appreciate the need for having specialized modules in Python for handling tables and should also make you well versed with loops and string operations. Even if you do know, do not use any modules that specialize in table handling. Bad File Names --------------- Imagine that a whole directory of files has been given to you. Sadly, the person who created them used spaces in the file names. This is causing you a lot of inconvenience in using certain programs on them. Once and for all, you decide to end the story and rename all the files to replace spaces with underscores. Go ahead, write a program to do this. Remember, the program should be able to recurse into sub-directories. You will need the "os" and "os.path" modules for this. Optional: Even apostrophes in file names is a bad idea. Can you extend the program to replace these with an underscore too? Python Switch Statement ------------------------ Write a program that accepts a single digit number from the user through the keyboard. Depending on whether the user enters 1, 2, 3, 4 or 5 the program must display "NGC 4254", "Cygnus A", "Sgr A*", "M31" or "IC 51" respectively. And yes, here is the catch. YOU ARE NOT ALLOWED to use "if" or any variation of it. If you get this, see if you can further extend the program to print "BLACK HOLE" in case a person enters anything other 1,2,3,4 or 5. Any idea why you think this assignment is called the "Python switch statement"? Timing the Code --------------- Write a function called time_checker() which accepts another function and an integer as input. The function must run the code that integer number of times and return the mean time taken by the supplied function to execute. Then design some function of your choice which does an arithmetic operation, measure the time taken. Can you further compare the mean time taken for adding two numbers vs multiplying two numbers? (You will need a module called "time" for this exercise.) The Robber's Language ---------------------- Write a function translate() that will translate a text into "rövarspråket" (Swedish for "robber's language"). That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon". (You will need the "in" keyword for this exercise, which was not covered in the talks. In iPython type the following statements. Infer what "in" does and then use it as necessary in this program. 'a' in 'string' 'i' in 'string' Log Table Generator -------------------- Produce a pretty (i.e. formatted) logarithmic table for the numbers 0.1, 0.2,... 10.0 which gives the logarithms for bases 2, e, and 10 to 7 digits. Hint: math.log lets you specify the base. Use ”%10.7f” for string formatting. Did you know that Python 3's later versions will get rid of this style of formatting? So, why not JD to Date converter ---------------------- Write a python code to convert JD to YYYY/MM/DD and vice versa. The input should be accepted through keyboard. Optional: Try writing a program that can judge whether the input provided by the user is JD or YYYY/MM/DD instead of asking a user to choose which way the conversion should happen. Mean, Median, MAD --------------------- Write a function to return Mean, Median and MAD of a list of number read from a text file. (For MAD's formula see: http://en.wikipedia.org/wiki/Median_absolute_deviation ) URL access from python ------------------------ Given text file contains a list of urls and file names to be saved in your machine. Write a python code to read one url at a time, download and save it to hardisk with proper filename. (You will need to use the module urllib) Literary Analysis ------------------ Write a program that will take a text file as input and return a report listing alphabetically all the words in the file and the number of occurances of each. Math Game Quiz --------------- Create a game program that accepts User Name. Then a difficulty level, say 1, 2 or 3. Then using random combinations of two integers (integers betweeen 1 and 10 for level 1, 1 and 25 for level 2 and 1 and 100 for level 3) and operators, a question in arithmetic should be posed and an answer should be accepted from the user. At the end of 10 questions, a score card should be presented. A grade should be assigned. You can choose your own grading system. Comparing Two Lists ------------------- Two files, each containing a list of items should be accepted by your program via command line and then the output should comprise of the following table Number of words in A | Number of words in B No. Words in A not in B | No. of Words in B not in A No. Words Common | No. of Words Common List of Common Words You will want to explore the set datatype in Python to ease this exercise. But if you should choose to define your own way without exploring the set datatype, you are welcome.