#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 |
For example, if your first name is Eric, you would use Euros. From the table above, we have that one dollar is worth 0.77 euros. You should begin the program by printing out your name. On each line, your program should write the number of dollars and the corresponding number of your currency. For example:
Eric's converting program Dollars: Euros: 1 0.77 2 1.53 3 2.3 4 3.07 5 3.84
Your 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.
The following draws a 4-sided figure or square:
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: 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
starting value: | color_rgb(5,0,0) | color_rgb(0,51,0) | color_rgb(0,0,59) |
---|---|---|---|
ending value: | color_rgb(255,0,0) | color_rgb(0,255,0) | color_rgb(0,0,255) |
shape: | a circle whose x-coordinate and radius increase each step | a circle whose x and y coordinates increase each step | skinny, full height rectangles whose x coordinate increases each step |
Choose your favorite color of red, green, and blue. Let startingValue be the last two digits of your Blackboard username (long number usually starting with 2011....) and set your favorite part of the color to that number (and the other two values to zero, as above). So, for example, if the last two digits of your username were 59 and your favorite color is blue, you would use startingValue = 59 and color_rgb(0,0,startingValue). Your program should display at least 100 objects (circles, rectangles, or what ever you choose). The first object should be your favorite color with startingValue. The last object should have the same color with startingValue replaced by 255. The object should get increasingly lighter.
Hint: Use (255-startingValue) objects and then you can let the color increase by 1 each time. To give a smooth transition, use the setOutline() function on your object to make the outline color match (the default is white outlines on objects).
Example: "hello" becomes "khoor".
Character replacement at the end of the alphabet, wraps around to the beginning.
Example: "wxyz" becomes "zabc"
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
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 o
Hint: Make sure all place names are the same length. If they are not add spaces to the shorter names to make them all equal length. If you have a list of strings, places, then places[0] refers to the first place in your list, in this case 'San Francisco'. Also, places[0][i] refers to the ith character of the first word in your list. Example: places[1][3] refers to the letter 'i' in the string 'Christchurch'.
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 a
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
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.
"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/):
And a simple plotting of the data:
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)
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.
Draw a flower by repeatedly calling your function. Your flower should have at least 10 pedals. 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").)
You should include in the file a main() that calls your function several times to demonstrate that it works.
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
Here is a sample run of the program:
Please enter clothing prices, separated by commas: 100, 9.99, 200, 159.99 Your receipt: 100.00 9.99 200.00 T 159.99 T --------- 500.58
(The `T' indicates which items are taxed. To make the receipt look nice, you can use format() and rjust() functions.
For example,
This program decodes a textual message Each character is replaced with the character 2 places ahead in the alphabet. The characters "'", ".", "(", ")", and " " are not decoded. Please enter the message to decode: 250 Bedford Park Blvd W, 10468 The decoded message is: 472 Dgfhqtf Rctm Dnxf Y, 32680
(Hint: try the original program on the message below. What are the differences in the encoded messages it produces and the output above?)
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.
One sample run of the program:
Please enter the amounts to credit/debit from your account, separated by commas: -500,100.01,-1000,333.33,85.02,-200 Beginning Balance: $1000.00 Amount: -500 Balance: $500.00 Amount: 100.01 Balance: $600.01 Amount: -1000 Your balance has dropped below 0! Please contact the bank immediately!
Another sample run of the program:
Please enter the amounts to credit/debit from your account, separated by commas: 5.00,123.01,-600,7.89,-99.99 Beginning Balance: $1000.00 Amount: 5.00 Balance: $1005.00 Amount: 123.01 Balance: $1128.01 Amount: -600 Balance: $528.01 Amount: 7.89 Balance: $535.90 Amount: -99.99 Balance: $435.91 Your final balance is: $435.91
For example,
Welcome to Hangman! The secret word has 6 unknown letters: _ _ _ _ _ _ Guess a letter: K There is no K, mistake count = 1 The secret word has 6 unknown letters: _ _ _ _ _ _ Guess a letter: A There is no A, mistake count = 2 The secret word has 6 unknown letters: _ _ _ _ _ _ Guess a letter: T There is a T, mistake count = 2 The secret word has 5 unknown letters: _ _ T _ _ _ Guess a letter: H There is a H, mistake count = 2 The secret word has 4 unknown letters: _ _ T H _ _ Guess a letter: E There is no R, mistake count = 3 The secret word has 4 unknown letters: _ _ T H _ _ Guess a letter: R There is no R, mistake count = 4 The secret word has 4 unknown letters: _ _ T H _ _ Guess a letter: I There is no 1, mistake count = 5 The secret word has 4 unknown letters: _ _ T H _ _ Guess a letter: N There is no R, mistake count = 6 The secret word has 3 unknown letters: _ _ T H _ N Guess a letter: P There is a P, mistake count = 6 The secret word has 2 unknown letters: P _ T H _ N Guess a letter: Y There is a Y, mistake count = 6 The secret word has 1 unknown letters: P Y T H _ N Guess a letter: O There is a O, mistake count = 6 The secret word has 5 unknown letters: P Y T H O N Congratulations! You won the game!
To make the programming simpler, you may choose a secret word where every letter occurs at most once, as long as your word has over 5 letters. As before, make sure that your word is different from others' words so the cheat-checking programs don't accidently match your program and that the word is not obscene (since it will be flagged by the Blackboard system).
angle = randrange(0,360) tom.right(angle) tom.forward(10)
Write a simulation to answer this question. That is, write a program that will randomly generate 100,000 strings of length 5 and count the number of strings that match "to be". You may assume that your strings are lower case letters and spaces only. That is, when you generate your string, you are choosing from the 27 characters:
[' ','a','b','c','d',...'y','z']
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
A sample run of your program should look something like (but not identical due to the randomness of the simulation):
2 : 308 3 : 629 4 : 932 5 : 1231 6 : 1230 7 : 1242 8 : 1343 9 : 1198 10 : 938 11 : 617 12 : 332
In your submitted file, include a main() function that demonstrates that the sort algorithm works.
from turtle import * def mystery2(t,x): for i in range(6): forward(x) right(60) if x > 0: mystery2(t,x-10) t = Turtle() mystery2(t,50)Modify the program so that it draws nested triangles instead.
Eric, Sameh, Ali, Tom, Kostos, Tony, KatherineAnd your name is Kostos, the ending list would be:
Kostos, Sameh, Tom, Tony, Ali, Eric, KatherineIf your name is Eric, the ending list would be:
Eric, Katherine, Kostos, Sameh, Tom, Tony, Ali
In your submitted file, include a main() function that prints out your name and demonstrates that the sort algorithm works.
Hint: you only need to change the "comparison" part of the sort, but you will need to make it more complicated. If you are trying to figure out which of two strings, say string1 and string2 come first, you need to compare them first to your name. If both are before or both are after your name, you can compare in the same way as before. If one of the strings comes before your name and the other after your name, you will have additional comparisons.
algorithm stoogesort(L, i, j) if L[j] < L[i] then swap L[i] and L[j] if j - i > 1 then t := (j - i + 1)/3 stoogesort(L, i, j-t) stoogesort(L, i+t, j) stoogesort(L, i, j-t) return L stoogesort(L, 0, length(L)-1)In your submitted file, include a main() function that demonstrates that the sort algorithm works.
algortihm fern(turtle, size) if size > 4 Move turtle forward size/25 steps Turn turtle 90 degrees left fern(turtle, size*0.3) Turn turtle 180 degrees right fern(turtle, size*0.3) Turn turtle 90 degrees left fern(turtle, size*0.85) Move turtle backward size/25 stepsInclude a main program that calls your fucntion with a turtle and size of 500
Hints: