Using python
Part 3c: Custom Number Range
Make a copy of Part B and update it so that the user can choose to examine a specific range of numbers for prime numbers. Here's a sample running of your program:
Start number: 5 End number: -5 Start and end must be positive Start number: 5 End number: 3 End number must be greater than start number Start number: 5 End number: 23 5 7 11 13 17 19 23
Part 3d: Tabular Formatting
Print the prime numbers that you find within the given range so that only 10 numbers print per line. Align the numbers so that they stack neatly on top of one another in all cases (i.e. the table should line up no matter what number range you are analyzing). Here's a sample running of the program:
Start number: 1 End number: 100 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
And here's another running:
Start number: 1 End number: 1000 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997
Start number: 9900 End number: 10100 9901 9907 9923 9929 9931 9941 9949 9967 9973 10007 10009 10037 10039 10061 10067 10069 10079 10091 10093 10099
Please find the code below:::
1)
def checkPrimeNumber(a):
k=0
for i in range(2,a//2+1):
if(a%i==0):
k=k+1
if(k<=0):
return True
else:
return False
def printPrimeInRange():
while True:
start = int(input("Start number : "))
end = int(input("End number : "))
if(start<=0 or end<=0):
print("Start and end must be positive")
elif(end<start):
print("End number must be greater than start number")
else:
break
for num in range(start,end+1):
if checkPrimeNumber(num):
print(num)
printPrimeInRange()
updated
def checkPrimeNumber(a):
k=0
for i in range(2,a//2+1):
if(a%i==0):
k=k+1
if(k<=0):
return True
else:
return False
def printPrimeInRange():
while True:
start = int(input("Start number : "))
end = int(input("End number : "))
if(start<=0 or end<=0):
print("Start and end must be positive")
elif(end<start):
print("End number must be greater than start number")
else:
break
count = 0
for num in range(start,end+1):
if checkPrimeNumber(num):
count+=1
print("%4d"%num,end="")
if count%10==0:
print()
printPrimeInRange()
To create a Python program that allows the user to examine a specific range of numbers for prime numbers and prints the prime numbers in tabular format, we can use the following code:
pythonCopy codedef is_prime(num): if num <= 1: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return Truedef print_primes_in_range(start, end, items_per_line=10): primes = [num for num in range(start, end + 1) if is_prime(num)] for i in range(0, len(primes), items_per_line): print(" ".join("{:4}".format(prime) for prime in primes[i:i+items_per_line]))def main(): print("Enter the range of numbers to examine for prime numbers:") start = int(input("Start number: ")) end = int(input("End number: ")) if start <= 0 or end <= 0: print("Start and end must be positive.") elif end <= start: print("End number must be greater than start number.") else: print_primes_in_range(start, end)if __name__ == "__main__": main()
When you run this program, it will prompt you to enter the range of numbers to examine for prime numbers. After entering the start and end numbers, it will print the prime numbers within that range in tabular format, with 10 numbers per line.
You can copy and paste this code into a Python file (e.g., prime_numbers.py
) and run it using a Python interpreter. It will then prompt you to input the start and end numbers to examine for prime numbers and display the result in tabular format.
Using python Part 3c: Custom Number Range Make a copy of Part B and update it...
Source: 2014 Nielsen 72 Prime Numbers A prime number is a number that is evenly divisible only by 1 and itself. The prime numbers less than 100 are listed below. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Choose one of these numbers at random. Find the probability that a. The number is odd b. The sum of the digits is odd c....
write the code in C please 4. Write a logical function perfect Square that receives a positive integer number and checks if it is a perfect square or not. Note: perfect square numbers are 4, 9,16,25,36 etc.... Write a main function that makes use of the perfect Square function to find and print all perfect squares between nl and n2. nl and n2 are end values of a range introduced by the user. ■ (inactive CAT EXE) Enter end values...
CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive integers and prints every prime number between (and including) them Sample Input: prime(from: 0, to: 100) Sample Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...
(prime.cpp) A prime number is a number that cannot be formed by multiplying two smaller numbers (not including 1). For example, 2, 3, 5 are prime numbers but 4 (2*2) and 6 (2*3) are not. Write a C++ program that receives the start point and end point from user and displays all the prime numbers in this range. The program also receives how many numbers to display per row. No need to validate. Print the results in a tabular format....
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...
Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...
The task involves writing a C++ program that determines the prime numbers between 1 and 100. The steps you should follow to identify the prime numbers are the following. 1. The number 1 is not a prime number, so it should be scratched. 2. Starting from the first prime number, which is 2, you scratch all the numbers that are the multiple of 2. You should not scratch out 2 itself. 3. The next number in the sequence after the...
The following function is_prime() is not a very efficient prime number test: #include <stdio.h> int is_prime(int n) { int d; for (d = 2; d < n; d++) { if (!(n % d)) return 0; } return 1; } int main() { if (is_prime(7)) printf("Seven is Prime!\n"); return 0; } It is unnecessary to divide n by all numbers between 2 and n - 1 to determine if n is prime. Only divisors up to and including need to be...
1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...