#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.
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: 4 Month 1: $10 Month 2: $20 Month 3: $30 Month 4: $40
Please enter the number of days: 8 Day 1: $1 Day 2: $2 Day 3: $4 Day 4: $8 Day 5: $16 Day 6: $32 Day 7: $64 Day 8: $128
Please enter a line: I love python I LOVE PYTHON
Please enter a line: I love python You entered 13 characters.
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.)
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.
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
insert into customer (first, last, address) values ('FirstName', 'LastName', 'Address')A sample input file is mayorsAddresses.txt.
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.
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(): welcome() #Prints "Hello, world" to the screen x,y = userInput() #Asks user for 2 inputs and returns numbers entered d = calculate(x,y) #Returns the difference of the parameters displayResults(x,y,d) #Prints the two inputs, and d main()That is, write the functions welcome(), userInput(), calculate() and displayResults(). Submit a .py file containing all four functions you wrote, in addition to the main() function above.
def main(): welcome() #Prints "Welcome" to the screen age = userInput() #Ask the user for their age and return number entered y = calculate(age) #Using age, calculates year born displayResults(age,y) #Prints age and birth year main()(That is, write the functions welcome(), userInput(), calculate() and displayResults().) Submit a .py file containing all four functions you wrote, in addition to the main() function above.
def main(): welcome() #Prints "Welcome" to the screen age = userInput() #Ask the user for their age and return number entered y = retire(age) #Using age, calculates retirement year (year turns 65) displayResults(age,y) #Prints age and retirement year main()(That is, write the functions welcome(), userInput(), retire() and displayResults().) Submit a .py file containing all four functions you wrote, in addition to the main() function above.
You should include in the file a main() that calls your function several times to demonstrate that it works.
You should include in the file a main() that calls your function several times to demonstrate that it works.
In your submitted file, include a main() function that demonstrates that the sort algorithm works.
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.