Question

In: Computer Science

A prime number (or prime) is a natural number greater than 1 that has no posítive...

A prime number (or prime) is a natural number greater than 1 that has no posítive divisors other than 1 and itself. Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.

Solutions

Expert Solution

Code and output

Code for copying

def sum_prime(n):
sum1=0

  
for i in n:
count=0
if i>0:
  
for j in range(2,int(i/2)):
if i%j==0:
count+=1
if count==0:
sum1+=i
return sum1
n=list(map(int,input("enter the list: ").rstrip().split()))
print("The sum is {}".format(sum_prime(n)))

Code snippet

def sum_prime(n):
    sum1=0
   
    
    for i in n:
        count=0
        if i>0:
            
            for j in range(2,int(i/2)):
                if i%j==0:
                    count+=1 
            if count==0:
                sum1+=i
    return sum1        
n=list(map(int,input("enter the list: ").rstrip().split()))
print("The sum is {}".format(sum_prime(n)))

Related Solutions

A prime number is an integer greater than 1 that is evenlydivisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. 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 by 1, 2, 3, and 6.Write a Boolean function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, and false otherwise. Demonstrate...
A prime number is an integer greater than 1 that is evenly divisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Create a PrimeNumber application that prompts the user for a number and then displays a message indicating whether the number is prime or not. Hint: The % operator can be used to determine if one number is evenly divisible by another. Java
A prime number is an integer greater than 1 that is evenly divisible by only 1...
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Create a PrimeNumber application that prompts the user for a number and then displays a message indicating whether the number is prime or not. Hint: The % operator can be used to determine if one number is evenly divisible by another. b) Modify the...
Java program Prime Numbers A prime number is a natural number which has exactly two distinct...
Java program Prime Numbers A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a java program which reads a list of N integers and prints the number of prime numbers in the list. Input: The first line contains an integer N, the number of elements in the list. N numbers are given in the following lines. Output:...
1)Assume that the data has a normal distribution and the number of observations is greater than...
1)Assume that the data has a normal distribution and the number of observations is greater than fifty. Find the critical z value used to test a null hypothesis. Round to two decimal places. α = 0.07; alternate hypothesis H 1 is μ ≠ 3.24 LaTeX: \pm ± __________ 2)Use the given information to find the P-value. The test statistic in a right-tailed test is z = 0.21. Round to two decimals. 3)Find the P-value for the indicated hypothesis test. A...
1) How many positive integers are greater than 140, less than 30800 and relatively prime to...
1) How many positive integers are greater than 140, less than 30800 and relatively prime to 280.
Prove by strong mathematical induction that any integer greater than 1 is divisible by a prime...
Prove by strong mathematical induction that any integer greater than 1 is divisible by a prime number.
Write following program using Python: A positive integer greater than 1 is said to be prime...
Write following program using Python: A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that asks the user to enter a integer greater than 1, then displays all of the prime numbers that are less than or equal to the number entered. Last, create two files. One file will hold all of...
Problem 3 Write code in R or Rstudio (Programming) A prime number is an integer greater...
Problem 3 Write code in R or Rstudio (Programming) A prime number is an integer greater than one whose only factors are one and itself. For example, the first ten prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. A twin prime is a prime that has a prime gap of two. Sometimes the term twin prime is used for a pair of twin primes. For example, the five twin prime pairs are (3, 5),...
A number is a palindromic prime if it is a prime number as well as a...
A number is a palindromic prime if it is a prime number as well as a palindromic number (ie. it is the same number when the digits are reversed). For example, 10301 is a palindromic prime. Write a Python program to ask the user how many palindromic primes they would like to compute, and output the values with a maximum of 10 values per line. Your program should include the following functions: isPrime(number) - returns True or False isPalindrome(number) -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT