#Name: Herbert H. Lehman #Date: February 4, 2013 #This program prints: hello world def main(): print("Hello world") main()
Submit the following programs via Blackboard:
If your name begins with... | Use the currency: | $1 is worth: |
---|---|---|
A | Afghan Afghani (AFN) | 51.08 |
B | Bangladeshi Taka (BDT) | 80.58 |
C | Costa Rican Colon (CRC) | 499.38 |
D | Danish Krone (DKK) | 5.67 |
E | Euro (EUR) | 0.77 |
F | Falkland Island Pound (FKP) | 0.62 |
G | Guatemalan Quetzal (GTQ) | 0.13 |
H | Hungarian Forint (HUF) | 0.00456 |
I | Indonesian Rupiah (IDR) | 9639.99 |
J | Japanese Yen (JPY) | 83.85 |
K | Kenyan Shilling (KES) | 0.0116 |
L | Lebanese Pound (LPP) | 0.000664 |
M | Moroccan Dirham (MAD) | 0.118 |
N | Nepalese Rupee (NPR) | 0.0115 |
O | Omani Rial (OMR) | 0.384 |
P | Polish Zloty | 3.11 |
Q | Qatari Riyal (QAR) | 0.275 |
R | Russian Ruble (RUB) | 30.80 |
S | Somali Shilling (SOS) | 0.000619 |
T | Thai Baht (THB) | 30.59 |
U | Ukrainian Hryvna (UAH) | 8.10 |
V | Venezuelan Bolivar (VEH) | 4.30 |
W | Samoan Tala (WST) | 2.27 |
X | East Caribbean Dollar (XCD) | 2.70 |
Y | Yemeni Rial (YER) | 0.00477 |
Z | Zimbabwean Dollar (ZWD) | 361.90 |
Eric's converting program Dollars: Euros: 1 0.77 2 1.53 3 2.3 4 3.07 5 3.84Your program should print the information for 1, 2, ..., 10 dollars. You do not need to worry about formatting (we will talk about that more in Chapter 5), but you do need to calculate all 10 entries. Hint: modify the program from the Lab 2.
Your program should print out your name to the screen and then ask the user to enter a string. You should then print out how long the string is in terms of the length of your name (that is, the length of the user's string divided by your length). For example,
The measuring string is "Kate" Please enter a string: Hello world Your string is 2.25 Kate's long.While, if your name was Daniel, your program would look like:
The measuring string is "Daniel" Please enter a string: Hello world Your string is 1.8333 Daniel's long.
import turtle def main(): daniel = turtle.Turtle() #Set up a turtle named "daniel" myWin = turtle.Screen() #The graphics window #Draw a square for i in range(4): daniel.forward(100) #Move forward 10 steps daniel.right(90) #Turn 90 degrees to the right myWin.exitonclick() #Close the window when clicked main()Modify this program to draw a 6-sided figure or hexagon. Make sure to include the standard introductory comments at the beginning of your program as well as to change the name of the turtle to your name.
Please enter the number of days: 5 Day 1: $1000 Day 2: $500 Day 3: $250 Day 4: $125 Day 5: $62.5(Do not worry about formatting the amounts. We will discuss how to do that well in Chapter 5.)
Your program should print out your name to the screen and then ask the user to enter a string. You should then print out how long the string is in terms of the length of your name (that is, the length of the user's string divided by your length). For example,
The measuring string is "Kate" Please enter a string: Hello world Your string is 2.25 Kate's long.While, if your name was Daniel, your program would look like:
The measuring string is "Daniel" Please enter a string: Hello world Your string is 1.8333 Daniel's long.
Please enter the prices: 2.34, .99, 100, 81.05, 90 Your receipt: 2.34 0.99 100.00 81.05 90.00 ---------------- Total: 274.38(Hint: use the format() statement discussed in Chapter 5.)
Your program should print out the list regularly and vertically. For example,
['San Francisco', 'Christchurch ', 'Sydney ', 'Bangkok ', 'Copenhagen '] S C S B C a h y a o n r d n p i n g e F s e k n r t y o h a c k a n h g c u e i r n s c c h oHint: if you have a list of strings, places, then places[0][i] refers to the ith character of the first word in your list. Start by printing out the first place name vertically, then add in the others.
H e r b e r t H . L e h m a n e r b e r t H . L e h m a n H r b e r t H . L e h m a n H e b e r t H . L e h m a n H e r e r t H . L e h m a n H e r b r t H . L e h m a n H e r b e t H . L e h m a n H e r b e r H . L e h m a n H e r b e r t H . L e h m a n H e r b e r t . L e h m a n H e r b e r t H L e h m a n H e r b e r t H . L e h m a n H e r b e r t H . e h m a n H e r b e r t H . L h m a n H e r b e r t H . L e m a n H e r b e r t H . L e h a n H e r b e r t H . L e h m n H e r b e r t H . L e h m aHInt: one way to approach this is to store the name with the spaces:
"H e r b e r t H . L e h m a n"
01234567890123456789012345 This line has more than 20 characters. This one has less And this one has lots, lots, lots, more than 20 characters!and the user entered the length of 20, all lines longer than 20 would be wrapped to the next line:
01234567890123456789 012345 This line has more t han 20 characters. This one has less And this one has lot s, lots, lots, more than 20 characters!Hint: break the problem in to parts: first write a program that will print lines from a file to the screen (see Lab 6). Then modify your initial program to only print lines up to the length entered. And, to finish the program, then add in the code that prints lines that are longer than the length entered. Note you will have extra blank lines, if a short line is entered (we will discuss how to print different things depending on the length when we discuss decisions in Chapter 7) and you do not have to worry about lines being longer than 40 characters (i.e. no need to wrap a line more than once).
For example, if the file inputTemplate.txt contained:
New York, New York 11 March 2013 **INSERT NAME HERE** **INSERT ADDRESS HERE** Dear **INSERT NAME HERE**, Thank you for your service to New York City, and, in particular, to the education of its residents. Those in **INSERT ADDRESS HERE** appreciate it! Best wishes to **INSERT NAME HERE** and your family, --CUNY
A sample run of the program would be:
Please enter the name of the template file: inputTemplate.txt Please enter names of recipients: Herbert H. Lehman, Bernard M. Baruch, Fiorello H. LaGuardia Please list addresses: Bronx NY, New York NY, Queens NY Your customized letters are below: New York, New York 11 March 2013 Herbert H. Lehman Bronx NY Dear Herbert H. Lehman, Thank you for your service to New York City, and, in particular, to the education of its residents. Those in Bronx NY appreciate it! Best wishes to Herbert H. Lehman and your family, --CUNY New York, New York 11 March 2013 Bernard M. Baruch New York NY Dear Bernard M. Baruch, Thank you for your service to New York City, and, in particular, to the education of its residents. Those in New York NY appreciate it! Best wishes to Bernard M. Baruch and your family, --CUNY New York, New York 11 March 2013 Fiorello H. LaGuardia Queens NY Dear Fiorello H. LaGuardia, Thank you for your service to New York City, and, in particular, to the education of its residents. Those in Queens NY appreciate it! Best wishes to Fiorello H. LaGuardia and your family, --CUNY
Finish my python homework. Buy milk. Do laundry. Update webpage.Then the output file would be:
1. Finish my python homework. 2. Buy milk. 3. Do laundry. 4. Update webpage.
"date","close","volume","open","high","low" "16:00","720.11","1,919,799","720.71","723","716.68" "2012/12/19","720.1100","1918493.0000","720.7100","723.0000","716.6800" "2012/12/18","721.0700","3004838.0000","716.6000","729.1000","715.0500" "2012/12/17","720.7800","3034558.0000","705.5000","738.2800","704.0200" "2012/12/14","701.9632","2129893.0000","699.1700","707.8200","698.4300" "2012/12/13","702.7000","3443866.0000","715.9200","716.4750","699.5500" "2012/12/12","697.5600","2425774.0000","699.2300","703.5100","693.4800"(file from: http://www.nasdaq.com/symbol/goog/historical)
where the first line describes the columns and each subsequent line of the file describes the stock price on a given day, separated by commas. Note that the historical data (from Nasdaq) lists the information in reverse chronological order, while graphs of financial data always start with the oldest date first. Your graph should have the oldest date on the left, progressing to the newest date on the right.
Hint: You may assume that the price of any stock is positive and below $1000, so, the y-coordinates of your window should between 0 and 1000. You may also assume that you are graphing data from one year. There are at most 52 weeks * 5 business days/week = 260 days per year, so your x-coordinates should range from 0 to 260 (or a bit extra to make it look nice).
Here are some sample files you can use to test your program: (from http://www.nasdaq.com/):
![]() |
![]() |
![]() |
Old MacDonald had a farm, Ei-igh, Ee-igh, Oh! And on that farm he had a cow, Ee-igh, Ee-igh, Oh! Whith a moo, moo here and a moo, moo there. Here a moo, there a moo, everywhere a moo, moo. Old MacDonald had a farm, Ei-igh, Ee-igh, Oh!(Hint: use a function with two input parameters one for the animal and the other for the related sound)
Draw a flower by repeatedly calling your function. Your flower should have at least
10 petals. For example,
(Note: you can change the color that your turtle, using the function, color(). For example, if you turtle is called flower to change it's color to purple, write flower.color("purple").)
def main(): w = setUp() #Creates and returns a graphics window x1,y1,x2,y2 = userInput() #Asks user for 4 inputs and returns numbers entered displayLine(w,x1,y1,x2,y2) #Draws a line from (x1,y1) to (x2,y2) on window w conclusion(w) #Gets a mouse click and closes window w main()That is, write the functions setUp(), userInput(), displayLine() and conclusion(). Include all functions, including the main() above in the file you submit.
Sameh's Currency Converter Converts from dollars into Somali Shilling, Afghan Afghanis, Moroccan Dirhams, Euros, and Hungarian Forints. Choose a currency ('S', 'A', 'M', 'E', 'H'): h What amount: 1000 The chosen currency is: Hungarian Forints The converted amount is: 4.56
You should include in the file a main() that calls your function several times to demonstrate that it works.
For example, a call to the function, fixLine([9,2,15,7,1]) will first compare l[0] = 9 to l[1] = 2. Since 2 is less than 9, your function should interchange the two entries, resulting in the list:
[2,9,15,7,1]Next, your function should compare l[1] = 9 to l[2] = 15. 15 is bigger than 9, so, there is no need to interchange them, and the list stays the same:
[2,9,15,7,1]Continuing, the function compares l[2] = 15 to l[3] = 7 and interchanges them:
[2,9,7,15,1]The process repeats with l[3] = 15 and l[4] = 1, resulting in:
[2,9,7,1,15]
Note that your function will only fix the largest entry's position in line (if you run it repeatedly, it will put the rest of the entries in order).
Write a main function that will ask the user to enter a list of numbers (separated by commas) and then pass that list to your function. The main function should then print out the list resulting from your function.
While the user has not guessed the word, print out two messages: one that says whether the message that was entered is too short, just right, or too long. Your second message should tell the user if there guess was before or after in the ordering of strings. Your game should continue until they guess your secret string and then should print a message congratulating them. Hint: see Lab 9.
angle = randrange(0,360) tom.right(angle) tom.forward(10)
A sample run of your program should look something like (but not identical due to the randomness of the simulation):
2 : 292 3 : 536 4 : 810 5 : 1100 6 : 1428 7 : 1631 8 : 1439 9 : 1100 10 : 825 11 : 543 12 : 296
Hint: To submit your program, include the dice class and main() in the same file. No changes are needed to the button class or graphics module, so, no need to include those.
For this problem, you will read and graph values from a CSV file. A CSV file is a "Comma-Separated File," in which the values on each line are separated from each other by commas. Problem 28 used an example of a CSV file. This kind of file is used to represent data from all sorts of activities, to be downloaded from the Web.
Your file will contain labels for the x axis in the first row and labels for the y axis in the first column. All other values will be numbers, which may or may not be contained in quotes.
Write a function that accepts a line from a CSV file and returns a list of numbers. The numbers may or may not be contained in single or double quotes. This function should work for any CSV file in which the first column contains labels and the rest contain only numbers.
The sample file we are providing represents sectors of the gross domestic product from the first quarter of 2002 to the last quarter of 2012. Each line of the file represents one sector of the economy (Consumption, Investment, Net Exports, Government, and Residual). The first row of the file contains labels for the time periods (I2002 for first quarter of 2002, II2002 for second quarter of 2002, etc.), the first column contains labels for the sectors.
Next, write a main program that uses the function to create several graphs, each graph representing a single line of the CSV file. Numeric values appear in row 2, column 2 through the last row and last column, but they may be enclosed in single quotes or double quotes.
For example, if you read the file:
Time period, I2002, II2002,III2002, IV2002, I2003, II2003,III2003, IV2003 GDP,11467.1,11528.1,11586.6,11590.6,11638.9,11737.5,11930.7,12038.6 Consumption,7953.7,7994.1,8048.3,8076.9,8117.7,8198.1,8308.5,8353.7 Investment,1781.9,1803.4,1808,1808.3,1810.4,1821.8,1888.4,1959.9 Exports,-510.2,-534.6,-553.9,-595.2,-584.9,-612.4,-602.8,-614.6 Government,2250.4,2272,2290.4,2305.7,2300.9,2335.1,2342,2343.7 Residual,-27.9,-24,-16.8,-20.1,-18.8,-14.7,-11,-8.1You should display the graph:
You may include labels, but you do not have to.