Compose a program that takes three floats

Assignment Help Python Programming
Reference no: EM132356826

Question

1) Order check. Compose a program that takes three floats x, y, and z as command-line arguments and writes True if the values are strictly ascending or descending (x < y < z or x > y > z), and False otherwise.

2) Physics Equation. Compose a program that takes three floats x0, v0, and t from the command line, evaluates x0 + v0t - Gt2 / 2, and writes the result. (Note: G is the constant 9.80665. This value is the displacement in meters after t seconds when an object is thrown straight up from initial position x0 at velocity v0 meters per second.)

3) Continuously compounded interest. Compose a program that calculates and writes the amount of money you would have if you invested it as a given interest rate compounded continuously, taking the number of years t, the principal P, and the annual interest rate r as command-line arguments. The desired value is given by the formula pert.

4) Color conversion. Several different formats are used to represent color. For example, the primary format for LCD displays, digital cameras, and web pages, known as the RGB format, specifies the level of red (R), green (G), and blue (B) on an integer scale from 0 to 255. The primary format for publishing books and magazines, known as the CMYK format, specifies the level of cyan (C), magenta (M), yellow (Y), and black (K) on a real scale from 0.0 to 1.0. Compose a program that converts RGB to CMYK. Accept three integers -r, g, and b -from the command line and write the equivalent CMYK values. If the RGB values are all 0, then the CMY values are all 0 and the K value is 1; otherwise, use these formulas:

w = max(r/255, g/255, b/255) c = (w - r/255) / w m = (w - g/255) / w y = (w - b/255) / w k = 1 - w

Here's an example run:

$ python rgbtocmyk.py 75 0 130

cyan = 0.4230769230769229

magenta = 1.0

yellow = 0.0

black = 0.4901960784313726

5) Great circle. Compose a program that takes four float command-line arguments x1, y1, x2, and y2 (the latitude and longitude, in degrees, of two points on the earth) and writes the great-circle distance between them. The great-circle distance d (in nautical miles) is given by the formula derived from the law of cosines:

d = 60 * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))

Note that this equation uses degrees, whereas Python's trigonometric functions use radians. Use math.radians() and math.degrees() to convert between the two.

Use your program to compute the great-circle distance between Paris (48.87° N, -2.33° W) and San Francisco (37.8° N, 122.4° W), between Leningrad (59.9° N, -30.3° W) and San Francisco (37.8° N, 122.4° W), between Paris (48.87° N, -2.33° W) and Austin (30.27° N, 97.74° W), between Nashville airport (BNA) (36.12° N, -86.67° W) and LAX (33.94° N, -118.4° W),between Princeton (40.35° N, 74.65° W) and Paris (48.87° N, -2.33° W).

Here's an example run:

Note: the shape of the earth is more like a flattened spheroid than a sphere, so the formula above is only an approximation (up to around 0.5% error). Also, this formula is unreliable for small distances because the inverse cosine function is ill-conditioned.

Here is the Haversine formula:
a = sin2((L2-L1)/2) + cos(L1) * cos(L2) * sin2((G2-G1)/2) c = 2 *

arcsin(min(1, sqrt(a)))

# distance in radians distance = 60 * c # nautical miles

The Haversine formula is accurate for most distances, but it suffers from rounding errors when the points are (nearly) antipodal. The following formula is accurate for all distances.

delta = G1 - G2 p1

= cos(L2) * sin(delta) p2

= cos(L1) * sin(L2) - sin(L1) * cos(L2) * cos(delta) p3
= sin(L1) * sin(L2) + cos(L1) * cos(L2) * cos(delta) distance = 60 * atan2(sqrt(p1*p1 + p2*p2), p3)

This Kahan reference provides more details.

Reference no: EM132356826

Questions Cloud

Quality improvement and health care needs assessment : Explain how either a QI project could lead to a community health needs assessment or vice versa. Provide specific examples
Determine benefit that the simplified acquisitions methods : Determine the benefit that the simplified acquisitions methods provide to the small-business owner. Analyze how the federal government has created this process
Planning for the private and public sectors : What are the differences and similarities between strategic management and planning for the private and public sectors?
Several forces for organizational change : There are several forces for organizational change: workplace demographics, technology, globalization, market conditions, growth, and poor performance.
Compose a program that takes three floats : Compose a program that takes three floats x0, v0, and t from the command line, evaluates x0 + v0t - Gt2 / 2, and writes the result.
Discuss how the following can support the review : Discuss how the following can support the review, updating & maintenance of the workplace systems & procedures relating to managing safety & hazards?
Review and evaluation process for organisation : The client would like you to establish a continual assessment, review and evaluation process for their organisation.
Forego the training needs analysis : Why are companies so willing to forego the Training Needs Analysis step when it is so obvious that conducting a needs analysis is good business?
Implemented culture of ethical business behavior : Identify an organization that you have worked for or know about that has successfully implemented a culture of ethical business behavior.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd