1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alina [70]
4 years ago
11

Write a Python program that asks the user for a positive, odd value. Once the value is validated determine if the number is Prim

e (i.e., divisible only by itself and 1.)

Computers and Technology
1 answer:
Umnica [9.8K]4 years ago
5 0

Answer:

val = int(input("Enter a positive odd value "))

flag = True # let the number entered is alreay prime

if(val > 2 and val%2 == 1):  # prime numbers start from 2

   half = int(val/2);

   for div in range(2,half):  # dividing the number from 2 to half of its number

       if(val % div == 0): # if completely divisible

           print("Not prime")

           flag = False   # Changing the status of prime number as false

           break

   if(flag == True):

       print(val, "is a prime number")

else:

   print("Invalid input, Please Enter a valid positive odd number")

Explanation:

Steps:

1. Let us take input from the user using input() method.

2.  Initially, let the number is prime.

3. If the number is negative or even, the go to else part and ask the user for a valid input and terminate the program by giving a message to user.

(We actually check for values greater than 2 because 1 is not considered as  a prime number)

4. If the number is positive and odd, then we keep on dividing the number from 2 to half of its number.

(We actually check for values greater than 2 because 1 is not considered as  a prime number)

5. If the number is divisible, we change the status to False and break the loop.

6. If the flag is still True, we print that it is a Prime number else we print that it is not a prime number.

Please refer to the comments section as well and the attached image for proper indentation of the program.

You might be interested in
1. What are the benefits and drawbacks of keeping separate journals for individual accounts?​
astraxan [27]

Answer:

these are some benefits Keep track of multiple areas of interest. If you want to write extensively about your day-to-day life, your exercise goals, the movies you see, and the places you visit, you might feel more organized if you have a separate place to write about each topic.

3 0
3 years ago
Consider a hard disk with the following specifications :<br> 3.5 in diameter
AnnyKZ [126]

Answer:

usable capacity = 10 GB

Number of cylinders = 256

Block size = 4 KB

(1)Bytes in each cylinder = (10*230)/(256) = (10*222) = 40 MegaBytes

(2)Number of Blocks in each cylinder = (10*222)/(212) = 10K

(3)capacity of one track = 40 MegaBytes/(10*2) = 2 MB

Rotation speed = 3840 RPM

Number of rotations per second = 3840/60 = 64

Transfer rate = (2*64) = 128 MB/sec

Explanation:

6 0
3 years ago
What does the average function do in a spreadsheet?
givi [52]
This article describes like shows the formula syntax and usage of the AVERAGE<span>  function in Microsoft Excel</span>
8 0
4 years ago
If you cannot find a template on your computer that was appropriate for your task, what should you do?
DanielleElmas [232]

Answer:

The correct option for this question is File.

Explanation:

5 0
3 years ago
What does tiny ink link do?????
patriot [66]

Answer:

what is it

Explanation:

'tiny ink link'

8 0
3 years ago
Read 2 more answers
Other questions:
  • How to tell if screen or screen protector is cracked?
    5·2 answers
  • The rules of thumb designers use when creating a wireframe page
    8·1 answer
  • What does server manager utility do
    7·1 answer
  • Let's say that you're the sole IT person in your company, and your boss wants a way to block certain websites from employees. Wh
    6·2 answers
  • Discuss the importance of top management commitment and the development of standards for successful project management. Provide
    10·1 answer
  • Match letters from column B to Column A by looking at the picture above.
    11·1 answer
  • write a pay-raise program that requests a person's first name, last name, and current annual salary, and then displays the perso
    6·1 answer
  • PLEASE READ ( if you want ) Before i used to have over 30 brainliest and i was just trying to earn points so i could get to ace,
    9·1 answer
  • Plz help
    5·1 answer
  • What is one way object-oriented programming differs from procedural programming?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!