Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
All of these problems are for practice. You are freely encouraged to work together and you do not need to submit any of this work for a grade.
Write a program that asks a person for his or her name, and issues a greeting. A run of the program might produces the following (with the underlined portion being the user's response).
What is your name? Bugs Bunny Hello Bugs Bunny! |
Write a program that asks a person for his or her name, and then reformats that name to appear in the form last, first, as shown in the following.
What is your name? Bugs Bunny Bunny, Bugs |
Can you write a program in a way so that it works on the above example but also works when the user specfies a middle name or initial?
What is your name? Elmer J. Fudd Fudd, Elmer J. |
Write a program that can add two integers given by the user. Try to mimic the user interface from the following example:
Enter an integer: 42 Enter another integer: 29 42 + 29 = 71 |
Write a program that relies on the Pythagorean Theorem (A2 + B2 = C2) to compute the length of the hypotenuse of a right triangle, given the lengths of the other two sides
Enter length of first side: 42 Enter length of second side: 29 Hypotenuse length is 51.0392 |
Note: square roots can be computed with the sqrt function imported from the math module.
Write a program that takes a date of the numeric form month/date/year and converts it to the equivalent format date monthname year, demonstrated as follows.
What is today's date [mm/dd/yyyy]? 01/26/2010 26 January 2010 |
Try to design the program so that if there is a leading zero in the date, it is nor printed in the newly formatted string, as in
What is today's date [mm/dd/yyyy]? 01/05/2010 5 January 2010 |
Would your program still work if the user omits leading zeros in the month and/or year, as in the following?
What is today's date [mm/dd/yyyy]? 1/1/2010 1 January 2010 |
Write a program that lets the user enter a date in the form monthname date, year, and converts that date to the numeric form m/d/y, demonstrated as follows.
What is today's date? January 26, 2010 1/26/2010 |
If you are interested in always ensuring that the new format uses two digits for the month and year (e.g., 01/26/2010) read the documentation for help(str.rjust).