#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:
For example:
The fault is in our stars... Please enter a number: 2 * *
Another sample run:
The fault is in our stars... Please enter a number: 5 * * * * *
Note: your program should have a statement you like (different from the sample and unique to you, so that the cheat-checking program does not flag it as someone's work) and print a character you choose (again, different from the character chosen above).
1. Ask the user for the size of their apartment in square meters (size) 2. Convert the size to square feet using the formula: convertedSize = size * 10.764 3. Print out the converted size.
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, ..., 5 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 5 entries.
1. Ask the user for the number of days until finals. 2. Print out the weeks until finals (weeks = days // 7) 3. Print out the leftover days (leftover = days % 7)
Here is a sample run of the program:
Please enter a number: 5 Please enter a number: 2015 Please enter a number: -100 Please enter a number: 3 Please enter a number: -999 Please enter a number: 8 Please enter a number: 67 Please enter a number: 19 Please enter a number: 17 Please enter a number: -1234 The total is -199
Here is a sample run of the program:
Please enter a letter: I Please enter a letter: l Please enter a letter: o Please enter a letter: v Please enter a letter: e Please enter a letter: P Please enter a letter: y Please enter a letter: t Please enter a letter: h Please enter a letter: o Please enter a letter: n Please enter a letter: ! Please enter a letter: ! Please enter a letter: ! Please enter a letter: ! The string is: IlovePython!!!!
Running sums: | Running products: | Accumulating Strings: | Accumulating Lists: | |
---|---|---|---|---|
Initialization: | sum = 0 | prod = 1 | s = "" | To be explained after Chapter 5... |
Update Action: | for ... sum = sum + newValue |
for ... prod = prod * newValue | for ... s = s + newValue |
Repeat 45 times: Walk forward 100 steps Turn right 92 degreesYour output should look similar to:
You may use any combination of turtle commands, but your image should have 9 by 9 grid shown above.
Hint: Resize the drawing canvas to give coordinates that are easier to use (see Lab 4).
For example, if the user enters the following at the Python shell:
Please enter coordinates: 2,1 Please hit the enter key to continue:We draw the turtle at 2,1 (for reasons that will become apparent later, we're representing our turtle by the number "2"):
After the user hits the enter key, we have:
Hint: break the problem down into pieces:
See Lab 4 for an example of a multi-part program with turtles.
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
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):
1. Prompt the user to enter a string and call it s. 2. Let l be the length of s. 3. For i from 0 upto l-1: 4. print s[0:i] 5. For i from 0 upto l-1: 6. print s[i:l] 5. Print a closing statementHere is a sample run of the program:
Enter string: a man a plan a canal panama a a a m a ma a man a man a man a a man a a man a p a man a pl a man a pla a man a plan a man a plan a man a plan a a man a plan a a man a plan a c a man a plan a ca a man a plan a can a man a plan a cana a man a plan a canal a man a plan a canal a man a plan a canal p a man a plan a canal pa a man a plan a canal pan a man a plan a canal pana a man a plan a canal panam a man a plan a canal panama man a plan a canal panama man a plan a canal panama an a plan a canal panama n a plan a canal panama a plan a canal panama a plan a canal panama plan a canal panama plan a canal panama lan a canal panama an a canal panama n a canal panama a canal panama a canal panama canal panama canal panama anal panama nal panama al panama l panama panama panama anama nama ama ma a Thank you for using my program!
Here is a sample interaction:
Enter line: Sing me no song, read me no rhyme line character count is 33 Enter line: Don't waste my time, show me! line character count is 29 Enter line: Don't talk of June, don't talk of fall line character count is 38 Enter line: Don't talk at all! line character count is 18 Enter line: Show me! line character count is 8 The number of characters entered is: 126
Please enter your list of names: Falcon, Claudio; Ford, Eric; Owen, Megan; Rogers, Josh; St. John, Katherine You entered: Claudio Falcon Eric Ford Megan Owen Josh Rogers Katherine St. John Thank you for using my name organizer!
For example, if your text file contained:
Input: first, get the input Process: then do the calculations Output: and last, print the results !!!
Then a sample run of your program would look like:
Please enter your file name: myFile.txt Your file in upper case letters is: INPUT: FIRST, GET THE INPUT PROCESS: THEN DO THE CALCULATIONS OUTPUT: AND LAST, PRINT THE RESULTS !!!
For example, if your text file contained:
Sing me no song, read me no rhyme Don't waste my time, show me! Don't talk of June, don't talk of fall Don't talk at all! Show me!
Then a sample run of your program would look like:
Enter file name: song.txt Line character count is 33 Line character count is 29 Line character count is 38 Line character count is 18 Line character count is 8
For example, if your text file contained:
Input: first, get the input Process: then do the calculations Output: and last, print the results !!!
Then a sample run of your program would look like:
Please enter your file name: myFile.txt The first letters of the lines in your file are: I P O !
For example, if your file contained:
8.0 -2.5 100.0 6.5
Then a sample run of your program would look like:
Please enter your file name: nums.txt The sum of your numbers is 112.0.
For example, if your file contained:
-2.5, 2.0 8.0 100.0, 3.0, 5.1, 3.6 6.5
Then a sample run of your program would look like:
Please enter your file name: nums.txt The sum of your numbers is 125.7.
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.
from wikipedia: NY-NJ-CT Tri-State Area The NY metropolitan area includes the most populous city in the United States (NY City); counties comprising Long Island and the Mid- and Lower Hudson Valley in the state of New York; the five largest cities in NJ and their vicinities; six of the seven largest cities in CT and their vicinities; and five counties in Northeast Pennsylvania.Then the output file should be:
from wikipedia: New York-New Jersey-Connecticut Tri-State Area The New York metropolitan area includes the most populous city in the United States (New York City); counties comprising Long Island and the Mid- and Lower Hudson Valley in the state of New York; the five largest cities in New Jersey and their vicinities; six of the seven largest cities in Connecticut and their vicinities; and five counties in Northeast Pennsylvania.Hint: do each replacement one-by-one, that is, first get your program to replace all the "NY"s with "New York"s and then go on to the next states.
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.
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 "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.
Hint: This problem can be approached as an "accumulator", where we accumulate lists:
Running sums: Running products: Accumulating Strings: Accumulating Lists: Initialization: sum = 0 prod = 1 s = "" li = [] Update Action:
for ...
sum = sum + newValuefor ...
prod = prod * newValuefor ...
s = s + newValuefor ...
li.append(newValue)
Hint: See problem above.
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).
In your file, you should include 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 file, you should include a main() that allows the user to enter a number and calls your function to demonstrate that it works.
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).