#Name: Herbert H. Lehman #Date: September 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.
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.
Repeat 45 times: Walk forward 100 steps Turn right 92 degreesYour output should look similar to:
Please enter the number of days: 4 Month 1: $10 Month 2: $20 Month 3: $30 Month 4: $40
Please enter a string: Look behind, look here, look ahead You entered (shouting): LOOK BEHIND, LOOK HERE, LOOK AHEAD But better (whispering): look behind, look here, look ahead
Please enter a line: I love python You entered 13 characters.
Note: Use characters in your output, even if it is not grammatically correct (i.e. "1 characters"). We will discuss how to fix this by making decisions in Chapter 7.
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.
A sample of Caesar cipher disk (from en.wikipedia.org/wiki/Caesar_cipher) with an offset of 13 (that is, every letter in plain text goes to one 13 letters to its right):
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.38Hint: 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.
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.
For example, if the file inputTemplate.txt contained:
New York, New York 11 October 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 October 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 October 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 October 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.
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)
from turtle import * def main(): myWin = turtle.Screen() #The graphics window tristan = turtle.Turtle() #Tristan will be our turtle for this program drawStem(tristan) #Draw a green stem for i in range(20): drawPetal(tristan,"blue") #Draws a blue petal for our flower drawPetal(tristan,"purple") #Draws a purple petal for our flower myWin.exitonclick() #Close the window when clickedThat is, write the functions drawStem() and drawPetal(). Include all functions, including the main() above in the file you submit. Sample output of the program:
(Note: you can change the color that your turtle, using the function, color(). For example, if you turtle is called tess to change it's color in stringColor, write tess.color(stringColor).)
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.
Here is an example of the program:
Enter your birth year: 2005 You are under 18. You are under 21.And another sample run:
Enter your birth year: 1995 You are over 18. You are under 21.Hint: Split the problem in half, and first write the code that tests if the birth year is greater than currentYear - 18 = 2014 - 18 = 1996, then work on the second part. See Lab 10.
You should include in the file a main() that calls your function several times to demonstrate that it works.
Hint: See Lab 11.
You should include in the file a main() that calls your function several times to demonstrate that it works.
Hint: See Lab 11.
Modify this program to allow the user also to specify with the following symbols:
Submit your modified program (including a comment at the top of the program with your name).
Hint: See Lab 12.
For example, the input file NY.TXT starts out:
NYF1910Mary,1922 NYF1910Helen,1290 NYF1910Rose,990 NYF1910Anna,951 NYF1910Margaret,926 NYF1910Dorothy,897 NYF1910Ruth,712 NYF1910Lillian,648 NYF1910Florence,604 NYF1910Frances,589 NYF1910Elizabeth,579 NYF1910Mildred,562Here a two sample runs of the program:
Please enter the file name: NY.txt Please enter the minimum length: 5 The first name with length 5 or more is: Helen Thank you for using my name length searching program!and
Please enter the file name: NY.txt Please enter the minimum length: 9 The first name with length 9 or more is: Elizabeth Thank you for using my name length searching program!
Hint: The program from the lab looks at every line of the file, but this program is a bit different in that it stops after it finds a long enough name. To do this, you need to change the loop to an indefinite loop (i.e. a while loop) or figure out how to break out of a definite loop (i.e. the for loop).
In your submitted file, include a main() function that demonstrates that the sort algorithm works.
Hint: See Lab 14.