Solve step by step

Description

Solve each question as instructed.

Don't use plagiarized sources. Get Your Custom Assignment on
Solve step by step
From as Little as $13/Page

Common mistakes that cost points:

All problems:

no PDF file
not following requirements 100%, e.g. changing function names or arguments

Problem 1:

using the wrong formula for he roots
wrong number of points for the plot
no screenshot in the PDF file

Problem 2:

using some algorithm found online instead writing your own trivial algorithm: you must submit your own original work.
not generating ALL possible tuples, e.g. finding (3, 4, 5) and omitting (4, 3, 5)
not including n in the loops

Problem 3:

printing results inside the required functions instead of returning the results

Problem 4:

using the wrong number of points
table formatting
missing the screenshot


Unformatted Attachment Preview

Python Programming
Homework 1
Instructor: Dr. Ionut Cardei
The following problems are from Chapters 1 – 5.
For full credit:
 make sure you follow exactly all requirements listed in this document,
 the program must have all required features and run as expected,
 follow the coding style taught in the book. Check out the Google Python Style Guide.
 upload on Canvas: the PDF file with all solutions plus the .py source files, in this order.
First, write the solution to a problem i in in a Pyhton file pi.py, for i=1…n.
Then, paste your answers into a new Word document called h1.doc. When done, convert it to PDF and
upload the PDF version (h1.pdf) and the solution .py files on Canvas.
The PDF file is very important: the instructor will write comments on top of the PDF file on Canvas for
you to read and learn from your mistakes.





Write your full name at the top of the file and add a heading before each problem solution.
List the solutions in the PDF file in the given order, 1, 2,.…
Syntax highlighting for the code pasted in the Word file makes it more readable and helps avoid
grading mistakes. Pasting from Spyder (or another IDE) into Word may preserve the Python
colors and styles. If not, consider using http://hilite.me/ or some other online service.
The problems are missing some details (e.g. on design, some method names). Where
unspecified by requirements, feel free to make your own decisions on design and
implementation as long as they comply with the book material, coding style, and don’t
contradict the requirements. If in doubt, ask on the Homework Q&A Forum, or ask the
instructor by email.
You have unlimited attempts to upload this assignment, but only the last one before the deadline
will be graded.
IMPORTANT:
Your solution must be your own original work and it must NOT include code that was shared or
copied from somewhere else. Doing otherwise is against the FAU Code of Academic Integrity.
For this assignment the instructor will use a cheating detector application that finds submissions that
indicate code shared or copied.
Name each required .py file like this: px_Lastname_Firstname.py, Substitute x with the problem
number, and Lastname, Firstname with your own last name and first name.
Example: if the problem number is 2 and your name is Jane Austen, name the problem 2 source file
p2_Austen_Jane.py.
Problem 1. Quadratic Equations
A quadratic equation has the form:
2
a x + b x+ c=0
The two solutions (called roots) are given by the formula:
x 1,2=
−b±√ b2−4 a c
2a
(1)
Write a program with a loop that :
a) solves quadratic equations with coefficients read from the terminal,
2
b) visualizes the corresponding quadratic function y= ax +bx +c using the matplotlib.pyplot module
(replacing module pylab used in the book).
Details:
1. The program consists of a main while loop (an infinite loop) in which the user is prompted to enter
values for coefficients a, b, and c. Assume the user types valid float numbers from the terminal. The
program converts the input to float type and then uses formula (1) above to compute solutions x1 and
x2, as follows:



2
if b − 4 ac 0 then the solutions are distinct and the program displays “two solutions: “
followed by the values of x1 and x2.
To keep the problem simple we can assume that the user never enters a value for coefficient a that is
equal to 0.
To stop the loop and end the program the user just types the ENTER key instead of the string for
coefficient a.
2. Within the main loop, after printing the values of the real solutions (if any) to the terminal the
2
program displays the graphic of the quadratic function y= ax +bx +c using the matplotlib.pyplot
module. The chart should use 150 points.
 If the function has real roots (one or two) make sure the roots are visible on the chart. E.g. if the
roots are -1 and 3 use a domain interval for values x (on the 0x axis) that includes -1 and 3, like
[-3, 5].
 If the function has no real roots, then center the function domain (x values) on the function’s
−b
minimum or maximum value, which is x opt=
.
2a
 Pick your own approach to select the function’s domain while complying with the above
requirements.
3. Insert the source code from p1_…py into the h1.doc Word document. The grader appreciates if you
use syntax highlighting, although it is not required.
4. Take a screenshot of the PC desktop showing the Spyder Python shell and the matplotlib figure
window and paste it in the h1.doc file after the source code.
The screenshot may look similar to this one:
Here is a sample user session on the terminal:
Enter a: 1↵
Enter b: 2↵
Enter c: 1↵
one solution: -1.00000
Enter a: 3↵
Enter b: 0↵
Enter c: 1↵
no real solutions
Enter a: 1↵
Enter b: -1↵
Enter c: -6↵
two solutions: x1=-2.00000 x2=3.00000
(user types CTRL-Z on Windows to enter EOF and finish the program)
Problem 2. Pythagorean Numbers
The lengths (a,b,c) of the three sides of a right triangle are related by this well-known formula:
a2 + b2 = c2.
A Pythagorean triple consists of three positive integer numbers bound by the above relation. An
example of a triple is (3,4,5).
Write program p2_…..py that reads from the terminal a positive integer n and that computes and
displays to the terminal all possible Pythagorean triples (a,b,c), where 0
Purchase answer to see full
attachment