5 challenge improved maxtrans rewrite maxtrans2 and

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: you're going to write a fancy name printing function, nice_name. The function should prompt the user for their name, and then display their name prominently for all to see. At a minimum, the function should display the name surrounded by * characters. However, you are encouraged to make your display as fancy as you want. A sample name display function might produce the following output: >>> nice_name() What is your name? Hermione ****************** * HERMIONE * ****************** (Don’t forget that the ‘*’ operator works for strings.) (3) Practicing string formatting CGMW ch. 3 #5 Given the variables x and y, which refer to values 3 and 12.5 respectively, use print to display the following messages. When numbers appear in the messages, the variables x and y should be used in the print statement. a) The rabbit is three. b) The rabbit is 3 years old. c) 12.5 is average. d) 12.5 * 3 e) 12.5 * 3 is 37.5. (Challenge – Improved max_trans) Rewrite maxtrans2 and maxtrans so that maxtrans2 calls maxtrans for both the “a, b, c route” and the “d, e route” (not just the “a, b, c route, as in project2). maxtrans2 should then (as before) return the maximum weight that can be transported from city to city. Note that maxtrans will need to modified so it can take a variable number of input arguments. (Look at the “Variable Parameters Lists” section of Chapter 12.) (Challenge – Oxford word challenge) An anagram, says the Concise Oxford Dictionary, is 'a word or phrase formed by transposing the letters of another word or phrase'. Can you transpose these words or phrases to make new words or phrases? a) Set up a variable to have the value of the original word. b) Answer the riddle. c) Use string operators and the original word to construct the answer string. (Extra challenge: use as few operations as possible.) Example: Rearrange lemon to make something else to eat. a) original = ‘lemon’ b) Answer: melon c) print(original[2] + original[1] + original[0] + original[3:]) 1. Rearrange the letters of the word eat to make something to drink. 2. Rearrange brush to make a kind of...
View Full Document

This note was uploaded on 02/12/2014 for the course CIS 122 taught by Professor Staff during the Spring '08 term at University of Oregon.

Ask a homework question - tutors are online