Hello all. I have some Python homework that I need some help with. I have been sick the past few days to attend class and am a little behind. This is a second level python course, and I wasn't able to take the first level either. Hopefully you can provide me with some solutions and I am sure I can learn from the solutions. Here are all of the mini questions. Please use as "basic" of functions and code as possible, as we are not expected to know any complex codes. Thanks for all help, I am sure to a professional, this would take only a few minutes.

Exercises

Solve the following small programming exercises by writing Python programs. Some of the exercises are stated vaguely: this has been done on purpose to make you think about possible solutions. Clarifications will be given in Course Discussion, in the labs and in class if necessary. The exercises are only roughly ordered by difficulty.

All input is from standard input and all output is to standard output.

(currenttime.py)

Your program should print the date and time of its execution in the following format

Printed on the Dss day of M, Y at HH:MM.

where

D is one or two digits of the day with no leading zeros,

ss is one of st, nd, rd, th, whichever appropriate for D,

M is the English name of the month,

Y is four digits of the year, and

HH and MM are the two digits for the hour and the minute respectively, printed with leading zeros.

You can use the datetime module in Python.

Sample output

Printed on the 26th day of July, 2012 at 12:37.

(blanks.py)

Your program replaces sequences of one or more consecutive identical whitespace characters with a single character identical to the replaced ones. At the end your program prints one additional line with the maximum number of consecutive identical whitespace characters in the input.

Sample input

ababa

ab ba

xxxxxxxxxxxxxxxxxxx

that is it followed by a lot of spaces .

no dot at the end

Output for sample input

ababa

ab ba

xxxxxxxxxxxxxxxxxxx

that is it followed by a lot of spaces .

no dot at the end

The largest run of consecutive whitespace characters was 47.

(convert.py)

Write a program which converts numerals from one base to another. Possible bases are between 2 and 62 and the following characters are to be used as digits

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

The digits for base n are the first n characters in the above string.

Input to you program consists of a sequence of lines which should be processed one by one. Each line contains two decimal numbers giving the source and the target base followed by a sequence of digits in the source base. Convert the input number expressed in the source base to the corresponding numeral in the target base.

Sample input

7 8 666

8 7 666

10 16 273

16 10 111

16 8 ffff

62 53 hgsdflkztyZTYWc10SAZ

62 23 hgsdflkztyZTYWc10SAZ

62 4 hgsdflkztyZTYWc10SAZ

62 10 hgsdflkztyZTYWc10SAZ

Output for sample input

526

1164

111

273

177777

6lMFwJNk0a8rl8PeuAAqs

hhadm3c8fea6jde4286821l9d0

21130132133021323030003200120232310202021011002003333133131

196163792841084734239402885221709789

(tally.py)

This program counts how many integer numbers occur on input, after treating all non-digit characters as whitespace. The last line of input contains one single word END. The output consists of the number and the sum of the integers in the format as indicated in the sample.

Sample input

Energy content of fuels KJoule/g KJoule/cc

Hydrogen 124.7 8.7

Coal C28H42 32.2 41.8

Wood C.32H.40O.22 17.5 14.2

Methane gas 61.1 .0044

Gasoline1 30.9e6 (J/liter))) ; => 3.090e+10

And -.23 here are some - 3.090e+10 negative -3.090e-10

numbers.

END

Output for sample input

There are 34 integers in the input summing up to 915.

(maplesyrup.py)

Peter has n bottles of maple syrup. He empties them one by one keeping all the bottle caps. For each k > 1 bottle caps he can get a new full bottle of maple syrup.

How many bottles of maple syrup can Peter have in total?

Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.

For each line of input, output one integer number on a separate line giving the maximum number of maple syrup bottles that Peter can have.

Sample input

4 3

10 3

100 5

1000000000 8

Output for the sample input

5

14

124

1142857142

(commperm.py)

This question is optional (Bonus marks).

Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.

Input consists of pairs of lines. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1,000 lowercase letters.

For each subsequent pair of input lines, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.

Sample input

pretty

women

walking

down

the

street

Output for the sample input

e

nw

et

Tweet This+ 1 thisPost To Linkedin