Question

write a function of quadratic choice. it must take in at least one parameter, and perform...

write a function of quadratic choice. it must take in at least one parameter, and perform some task. the reslut will be returned to main, and printed.


here is the sample but this sample still not complete because this sample still need to return root1 and root2 to the main.

sample:

def juneQuadratic(a,b,c):
  
root1 = (-b + math.sqrt(b**2 - (4*a*c)) )/2*a
root2 = (-b - math.sqrt(b**2 - (4*a*c)) )/2*a
return (root1,root2)

def main():
rootsTupleFromFunction = juneQuadratic(2,8,5)
print(rootsTupleFunction)
print("Root 1 is : " ,rootsTupleFromFunction[0])
print("Root 2 is : " ,rootsTupleFromFunction[2])
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

import math # math has to be imported for working with sqrt function

def juneQuadratic(a,b,c):
root1 = (-b + math.sqrt(b**2 - (4*a*c)) )/2*a
root2 = (-b - math.sqrt(b**2 - (4*a*c)) )/2*a
return (root1,root2)

def main():
rootsTupleFromFunction = juneQuadratic(2,8,5)
  
# Printing tuple returned from function call
print(rootsTupleFromFunction)
  
# Printing each root separetly
print("Root 1 is : " ,rootsTupleFromFunction[0])
  
# For two elements in tuple, indexing starts from 0 and ends with 1
print("Root 2 is : " ,rootsTupleFromFunction[1])
  
  
# Calling main function
main()

_____________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
write a function of quadratic choice. it must take in at least one parameter, and perform...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a,...

    Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a, b and c. Which will represent the coefficients in the quadratic equation ax2 + bx + c = 0. Print out the solutions (if any) of the quadratic equation. If no root exists (this happens if a == 0, or b2 <4ac) print the message No real root. Sample input/ user entries shown in red Corresponding output Enter a, b and c which represent...

  • 3. Produce the function quadratic(a,b,c) where a, b, and c are the coeffi- cients of the...

    3. Produce the function quadratic(a,b,c) where a, b, and c are the coeffi- cients of the quadratic ax2 + bx +c. The function should return: 1. a list of the two roots of ax2 + bx +c= 0, when two roots exist 2. the first root is the smaller of the two 3. if ax2 + bx +c=0 has no real roots, then return None. 4. if the quadratic has one real root only, then return a list with a...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • Task 4: a) Write a function named change() that has an integer parameter and six integer...

    Task 4: a) Write a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. b) Include the function written in part a in a working program. Make sure your function...

  • Please write individual functions solving each of the following problems: Print your name Print numbers 1...

    Please write individual functions solving each of the following problems: Print your name Print numbers 1 → 10 Print numbers N → M, where N and M are parameters to the function .Calculate and return a base B to an exponent E. B and E should be parameters to the function Convert Celsius to Fahrenheit Convert Fahrenheit to Celsius Take a numeric score as a parameter and return the associated letter grade Note, the functions that perform calculations should NOT...

  • #Write a function called check_formula. The check_formula #function should take as input one parameter, a string....

    #Write a function called check_formula. The check_formula #function should take as input one parameter, a string. It #should return True if the string holds a correctly #formatted arithmetic integer formula according to the rules #below, or False if it does not. # #For this problem, here are the rules that define a #correctly-formatted arithmetic string: # # - The only characters in the string should be digits or the five arithmetic operators: +, -, *, /, and =. Any other...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

  • Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that...

    Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...

  • [Python] Construct Tree Using Inorder and Preorder Given Preorder and Inorder traversal of a binary tree,...

    [Python] Construct Tree Using Inorder and Preorder Given Preorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root. Note: Assume binary tree contains only unique elements. Input format : Line 1 : n (Total number of nodes in binary tree) Line 2 : Pre order traversal Line 3 : Inorder Traversal Output Format : Elements are printed level wise, each level in new line...

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT