write easiest program to under stand:-
a) Python program that takes three coefficients (a, b, and c) of
a
Quadratic equation (ax2+bx+c=0) as input
and compute all possible roots
b).User defined function isprime(num) that accepts an integer
argument and returns 1 if the argument is prime, a 0 otherwise.
Write a Python program that invokes this function to generate prime
numbers
between the given ranges
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
import math
#method to print the roots of a quadratic equation
def print_roots(a, b, c):
#finding descriminant (b^2-4ac)
descriminant = (b * b) - (4 * a * c)
#if descriminant is less than 0, no roots
are there
if descriminant <
0:
print('No real
roots')
elif descriminant == 0:
#exactly one
root
root = -b / (2 *
a)
print('Root:', root)
else:
#two roots, applying
the equation to find the roots
#of quadratic
equation
root1 = (-b +
math.sqrt(descriminant)) / (2 * a)
root2 = (-b -
math.sqrt(descriminant)) / (2 * a)
#displaying two
roots
print('Root
1:', root1)
print('Root
2:', root2)
#method to check if a num is prime or not, returns 1 if prime,
0 if not
def isprime(num):
#any number less than 2 is not a prime
if num<2:
return
0
#looping from 2 to num/2, if any number in
this range divides
#num evenly, then num isnt prime
for i in
range(2,num//2):
if
num%i==0:
#not prime
return 0
return 1 #prime
def main():
#getting values for a,b and c, testing first
method
print('Enter three coefficients to
find the roots')
a=float(input('a: '))
b = float(input('b: '))
c = float(input('c: '))
print_roots(a,b,c)
#getting two integers, printing all prime
numbers between them
print('Enter starting and ending
range to print all primes')
n1=int(input('num1: '))
n2 = int(input('num2: '))
for i in
range(n1,n2+1):
if
isprime(i):
print(i,end=' ') #printing all on the same
line
print()
main()
#output
Enter three coefficients to find the roots
a: 1
b: 5
c: 6
Root 1: -2.0
Root 2: -3.0
Enter starting and ending range to print all primes
num1: 15
num2: 50
17 19 23 29 31 37 41 43 47
write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and...
Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...
Write a function that takes a list L = [a0,a1,....,an] of coefficients of a polynomial p(x) = a0xn+a1xn-1+...+ an as a single argument, factors the free coefficient , and prints all integer roots or an empty list if there is no integer roots in Python
#Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function named roll that #accepts an integer argument number_of_throws. The #function should generate and return a sorted #list of number_of_throws random numbers between #1 and 6. The program should prompt the user to #enter a positive integer that is sent to the function, #and then print the returned list. How would you do this?
write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...
10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate the real solutions to an equation in the form x 2 +bx+c=0 . Prompt the user to enter values for a, b, and c, then display the solutions. For the purposes of this assignment, you may assume that every equation will have two distinct, real solutions. Put your program in the Homework 1 folder on your K: drive. Here is a sample run of...
Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...
A prime number is a number that can be evenly divided by only itself and 1. For example, the number 5 is prime because it can be evenly divided by only 1 and 5. The number 6, however isn't prime because it can be evenly divided by 1,2,3, and 6. Write a bool function named isprime that takes an integer as an argument and returns true if the argument is a prime number or false otherwise. Use the function in...
Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program should prompt the user to enter a number n. The program will compute and display sum based on the series defined above. firstPrime: is 2 secondPrime: the first prime number after 2 thirdPrime: the third prime number …. nth prime: the nth prime number Your program must be organized as follows: int main() { //prompt the user to enter n //read n from the...
reword m the program into a design document diregard the m Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...
a prime number is a number that is only evenly divisible by itself and 1. for example the number 5 is prime because it can only be evenly divided by 1 and 5 the number 6 however is not prime because it can be divided evenly by 1,2,3 and 6. write a function name isPrime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. use this functuion in a...