primes

What is the problem with my code for finding whether a number is prime or not

What is the problem with my code for finding whether a number is prime or not Question: N = int(input()) flag = False if N <= 2: print(‘no’) for j in range(2, int(N**0.5)+1): if N%j == 0: flag = True if flag == False: print(‘yes’) else: print(‘no’) The logic is same everywhere I saw the …

Total answers: 2

Problem with simple prime number function

Problem with simple prime number function Question: I am trying to make a function to check if a number is a prime number based on the result of a modulo operation; so far so good but it seems to classify 9 as a prime number for some reason. def is_prime(x): if x <= 1: return …

Total answers: 3

How do you calculate the amount of prime numbers less than or equal to N?

How do you calculate the amount of prime numbers less than or equal to N? Question: I want to write a program that determines the amount of prime numbers less than or equal to N (variable containing user input). This is what I’ve got: N = int(input("Enter number: ")) count = 0 primes = [] …

Total answers: 3

How to get only a single output of the result in python program?

How to get only a single output of the result in python program? Question: I was writing a code in python to identify prime number. Here is the code n=int(input("Enter any integer")) for i in range(2,n,1): if n%i==0: print(n, " is not a prime number") break else: print("Prime number") But the problem is that I …

Total answers: 3

Python squaring a square rooted number gives a different result although it should be the original number

Python squaring a square rooted number gives a different result although it should be the original number Question: Im working on RSA so I’m dealing with very large numbers (308 digits). In RSA a number N is the product of 2 primes p and q. My N: 20254083928313901046078299908836135556415829454193867459405514358320313885965296062600909040071281223146837763723113350068483510086809787065437344845044248205975654791622356467691953988928774211033663314876745580293750456921795999384782277674803240671474563131823612882192899349325870727676292313218782419561 For the task I’m completing, I have …

Total answers: 2

Error: the encoded message must be a list of integers

Error: the encoded message must be a list of integers Question: I am creating a prime encryption program however I am running into a very perplexing error. This is my code: import random import datetime def decode(encoded_message, p): # Initialize an empty list to store the decoded message decoded_message = [] # Iterate over the …

Total answers: 1

Get Twin Primes as output from an inputted list

Get Twin Primes as output from an inputted list Question: I want to enter numbers separated by spaces as input and store them in a list. I want to get all twin primes in that list as output. If there’s no any twin primes in that inputted numbers I want to have an output "No …

Total answers: 2

sum of prime numbers

sum of prime numbers Question: I have an exercise: Write a program that takes the number n from the input and prints all cases of prime numbers whose sum is equal to n. For example: input is n = 13 and output is: 2 2 2 2 2 3 2 2 2 2 5 2 …

Total answers: 1

wanted to have a single list instead of multiple list showing prime numbers

wanted to have a single list instead of multiple list showing prime numbers Question: I tried to make a program that shows all prime number till the limit but the code shows each factor adding to the ans list. How do I fix this? limit = 34 num = [value for value in range(2, limit …

Total answers: 1

Timing operation with increasing list size – unexpected behaviour

Timing operation with increasing list size – unexpected behaviour Question: Problem: How long does it take to generate a Python list of prime numbers from 1 to N? Plot a graph of time taken against N. I used SymPy to generate the list of primes. I expected the time to increase monotonically. But why is …

Total answers: 1