Lab Topic 4 individual F23

.docx

School

Texas A&M University *

*We aren’t endorsed by this school

Course

102

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by ProfLightning103643

Report
Lab: Topic 4 (individual) ENGR 102 Lab: Topic 4 (individual) Deliverables Please complete the four programs described below. Each program is an individual assignment, but you may consult your teammates and others as you work. Please submit the following files to zyBooks. largest_number.py pretty_equation.py how_many_gadgets.py Activity #1: Largest number - individual Using conditional statements (i.e. statements like if-elif-else ) write a program named largest_number.py that takes as input from the user three (3) numbers from the keyboard and prints the value of the largest number. Your code should output in the format shown below. Example output (using inputs 1 , 2 , 3 ): Enter number 1: 1 Enter number 2: 2 Enter number 3: 3 The largest number is 3.0 Activity #2 : Pretty equation – individual A quadratic equation is an equation of the form A x 2 + Bx + C = 0 where A , B , and C are the coefficients of the equation. Write a program named pretty_equation.py that takes as input the coefficients A , B , and C and outputs the quadratic equation in a nice format. Your program should not print the coefficient “1” or a term with a coefficient “0” and should replace plus signs (+) with minus signs (-) for negative coefficients. Include one space between the sign and the term. You may want to review the string formatting document posted with Lecture 3. Use the output format shown below. You may assume the user only enters integers. Example output (using inputs -1 , -2 , 3 ): Please enter the coefficient A: -1 Please enter the coefficient B: -2 Please enter the coefficient C: 3 The quadratic equation is - x^2 - 2x + 3 = 0 Activity #3: How many gadgets - individual Assume a machine during its initial testing phase produces 10 gadgets a day. After 10 days of testing (starting on day 11), it begins to ramp up, producing 1 more gadget per day (11 gadgets on day 11, 12 on day 12, etc). On day 50 it reaches full speed, where it continues to run until on day 101 it stops producing gadgets. Write a program named how_many_gadgets.py that reads in a day (as a number) from the keyboard and reports the total number of gadgets produced from the initial testing phase up to and including the day entered. For example, entering 3 would report 30 gadgets. Your code should also . . . Check for inappropriate day numbers and message the user accordingly Echo the input in the output when you report the number of gadgets Based upon Dr. Keyser’s Original 1 Revised Fall 2023 SNR
Lab: Topic 4 (individual) Use the output format shown below Note : Do NOT use a loop. Part of the challenge in this program is for YOU to work out the model for how to compute gadgets produced in total, given the above information. Hint: Solve this problem by hand on paper first, then translate your solution to Python. A graph or diagram is extremely helpful . This approach is much easier than debugging some lousy Python code written before you understand the problem. Example output (using input 3 ): Please enter a positive value for day: 3 The sum total number of gadgets produced on day 3 is 30 Example output (using input -1 ): Please enter a positive value for day: -1 You entered an invalid number! Activity #4: Calculate roots - individual The roots of a quadratic equation are the values of x at which the equation evaluates to 0 . The well- known quadratic formula is often used to find these roots. Write a program named calculate_roots.py that takes as input the coefficients A , B , and C and outputs the roots of that equation. Be aware of the following: Use the output format shown below If the roots have an imaginary component (complex), use i when representing the imaginary term in the output. For example, you may output “ 3.0 + 7.0 i ” as a root. Be sure to handle the cases in which any or all coefficients are equal to zero o If A != 0 , there could be 2 real distinct roots, 2 real identical roots (one root of multiplicity 2), or 2 complex roots If there are two roots, output the larger root first o If A = 0 , we are left with Bx + C = 0 , a linear equation with one root o If A = B = 0 , we are left with C = 0 , so if the user entered a non-zero value of C , write a message to the screen indicating this error Example output (using inputs 1 , 2 , 1 ): Please enter the coefficient A: 1 Please enter the coefficient B: 2 Please enter the coefficient C: 1 The root is x = -1.0 Example output (using inputs 1 , 2 , -3 ): Please enter the coefficient A: 1 Please enter the coefficient B: 2 Please enter the coefficient C: -3 The roots are x = 1.0 and x = -3.0 Example output (using inputs 0 , 0 , 1 ): Please enter the coefficient A: 0 Please enter the coefficient B: 0 Based upon Dr. Keyser’s Original 2 Revised Fall 2023 SNR
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help