473,563 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prime numbers

1 New Member
Hello, help me please.

Write a function: User enters natural numbers A and B (A <B). The function prints all prime numbers separated by a space on the segment [A, B]
Nov 25 '21 #1
3 19704
dev7060
639 Recognized Expert Contributor
Write a function: User enters natural numbers A and B (A <B). The function prints all prime numbers separated by a space on the segment [A, B]
What have you done so far?
Dec 1 '21 #2
sumairaanwar
2 New Member
yes you can use a foe loop and in if condition use if number is divisible by 2 don't print but if number is not divisible y 2 print it



lower = int(input("Ente r the lower value:"))
upper = int(input("Ente r the upper value:"))
for number in range(lower,upp er+1):
if number>1:
for i in range(2,number) :
if (number%i)==0:
break
else:
print(number)
code pro zone
Feb 17 '22 #3
zermasroor
15 New Member
you can use if else statements to check the given condition of numbers this if will check all the vales one by one if you want to print those values you can different print statements separately for prime numbers or even numbers
for number in range(lower,upp er+1):
if number>1:

for i in range(2,number) :
if (number%i)==0:

break
else:

print(number)
Apartments for rent in Achrafieh Lebanon
Mar 12 '23 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2392
by: AshifToday | last post by:
this was my and my frineds little project in earlier classes, the program seperates the composite and prime numbers in two sections of the screen ===================== /* This program has been made by A & A Group. Muhammad Ali: Roll # 1462 Class A-2 , B.Sc.(Hons.) in C.S.
25
3857
by: johnmsimon | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is complicated. we are on a functions chapter. i am usung the square root to find the prime. so far i have accomplished this but i cant fgure how to divide...
60
1950
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers ending in 5 ..which obviously cannot be prime numbers) can anyone please help me out with the reason?? /*Generate Prime Numbers*/...
7
4888
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
5
2170
by: trillianx | last post by:
I know there has been lot of discussion on Prime numbers program but I have very specific question. Here is my program: # Find the prime numbers # This is a user input program that lets you decide if a number is a prime or not import math num = int(raw_input("Please enter a number: ")) #num = int(math.sqrt(num))
4
2589
by: Villanmac | last post by:
Hi i have made the following program to make a fucntion that determines if a number is prime. Than i am supposed to use this function to print all prime numbers between 1 and 10000. What am I doing wrong as mine dosnt work. Thank for any help ------------------------------------------------- #include <iostream>
2
1311
by: ujjawaltaleja | last post by:
//simply we are going to use the approach that the numbers that are divisble by prime numbers are not prime and the others are prime. #include<stdio.h> #include<math.h> int main() { int n,i,arr,size=0,j,temp; // array is for storing prime numbers scanf("%d",&n); // we will be finding prime numbers between 2 to n (both...
5
21005
by: guiromero | last post by:
I'm writing a program to calculate the number of prime numbers in a sequence. There's a variable called num that is given and then the program must calculate how many prime numbers there are from 2 (the smallest prime number) to num. It should be something like that: Enter a number greater than 1: 7 There are 4 prime numbers between 2 and 7....
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7876
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5201
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3628
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.