The following guidelines are expected for all homework submissions:
p = { x: 1, y: [ 4, {z: 2} ] }
. What is p.y[1]
?{call: "mark", next: {call: "ready", next: {call: "set", next: {call: "go", next: null}}}}
9 | 8 | 2 | -5 |
π | 7 | 2.8 | 6 |
-22 | 4 | 0 | 100 |
var p1 = {name: "Alice"}; var p2 = {name: "Bob", manager: p1}; p1.manager = p1;
p2.manager.manager.manager.name
in the previous question?prompt
, without assigning the result to
a variable, is useless. Would you agree or disagree? Explain your answer using the following
script (simulating a person who speaks but does not listen) for support:
prompt( "Hi, how are you today?" ); alert( "Gee, that's great!" );
all the time. Knowing that she is the kind of kid who loves technical, precise explanations of linguistic features, what do you tell her? (Note: You have to say more than just "Delete is an operator, kiddo.")delete player.winnings;
10 → 5 → 16 → 8 → 4 → 2 → 1
involves six steps.
If the initial value is 1, then you should report zero steps.split
the input string, producing an array that is then processed
by the acronym-generating code from this chapter.Exercise 1: Create a web page which has many parts and looks really "busy". You can have headers of all different sizes, paragraphs of text, tables with multiple columns and rows, images, ordered/unordered lists, and any other HTML parts that you would like to put on the page. Include a button that will create a listing of all the elements by type and display it to the footer area of the page. Write the JavaScript in a separate file
Exercise 2: Create a web page and matching JavaScript file that will implement a simple four-function calculator. There must be a text box for entering numbers, and buttons for add, subtract, multiply, and divide. You should also have a button for "equals" like a normal calculator. You don't have to make the calculator do anything fancy like maintaining running subtotals or trigonometric functions (you can if you want!) but try to make the page function like a "real" calculator as much as you can.
Exercise 3: Write a web page and a matching JavaScript file to solve
a quadratic equation of the form "Ax2 + Bx + C
", using the quadratic
forumula. (Look it up in your high school algebra book if you don't remember...) The web page
should have three boxes for use in entering the coefficients "A", "B", and
"C", and a button to click to produce the results. You may display the results in an
alert box, or on the web page, but if you opt for the alert box, you must only have one alert for
all results.
The following problems are from the book "Python for Everyone" by Cay Horstmann and Rance D. Necaise, ISBN 978-1-118-62613-9.
Exercise 4: (PYTHON PROGRAMMING — Business P2.36) An online bank wants you to create a program that shows prospective clients how their deposits will grow. Your program should read the initial balance and the annual interest rate from the user. Interest is compounded monthly. Print out the balances after the first three months. Write the program in Python (obviously). Here is a sample run of the program:
Initial balance: 1000 Annual interest rate in percent: 6.0 Balance after the first month: 1005.00 Balance after the second month: 1010.03 Balance after the third month: 1015.08
Exercise 5: (PYTHON PROGRAMMING — Business P2.37) A video club wants to reward its best members with a discount based on the member's number of movie rentals and the number of new members referred by the member. The discount is in percent and is equal to the sum of the rentals and the referrals, but it cannot exceed 75 percent. Write a Python program to calculate the value of the discount. Here is a sample run:
Enter the number of movie rentals: 56 Enter the number of members referred: 3 The discount is equal to: 59.00 percent
Exercise 6: (PYTHON PROGRAMMING — Science P2.39) The "dew point" temperature Td can be calculated (approximately) from the relative humidity RH and the actual temperature T by the formula:
Td = (b * f(T, RH)) / (a - f(T, RH)) where: f(T, RH) = ((a * T) / (b + T)) + ln( RH ) a = 17.27 b = 237.7 degrees C
Write a program that reads the relative humidity (a value between 0 and 1) and the temperature in degrees Celcius, and prints the dew point value. Use the Python function "log()" to compute the natural logarithm (the "ln" in the equation). Check your calculation with a few of the values located at this page. [NOTE: you'll have to convert the temperatures to degrees F.]
Exercise 7: (PYTHON PROGRAMMING — Science P2.43) According to
the Coulomb force law, the electric force between two charged particles of charge Q1
and Q2 Coulombs, that are a distance r meters apart, is given by the
formula
F = (Q1Q2) / 4 * Π * e * r². Write a program in
Python that calculates and displays the force on a pair of charged particles, based on the user input
of Q1 and Q2 Coulombs, and r meters.