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
Which of the following statements is true of offshore outsourcing?a. Improved telecommunication systems have increased its attra
irinina [24]
Jansjsfajhabsbsbsjs. Hbabajajajajanakslsk. Jshsbsjshsbshdjshjd ds
5 0
3 years ago
Read 2 more answers
You manage the DNS servers for the eastsim domain. You have a domain controller named DNS1 running Windows Server 2016 that hold
Ierofanga [76]

Answer:

..

Explanation:

...

3 0
3 years ago
Range is an example of a ______________.
k0ka [10]

Answer:

example in ( 4,6,9,3,7) lowest value is 3and highest is 9.

4 0
3 years ago
To change the left alignment of the items in an unordered list, you set the
shusha [124]

Answer:

b. left padding for the ul element

Explanation:

To change the left alignment of the items in an unordered list, you set the left padding for the ul element.

7 0
3 years ago
When you take action independent of direct instruction, you are showing _____. power power insubordination insubordination coura
Anarel [89]

Leadership qualities are the traits that define a person's ability to guide and organize. Independent action without any direct instruction is called initiative.

<h3>What is an initiative?</h3>

An initiative is an act of performing and executing the task independent of any instruction or guidance from someone. It is based on self-motivation rather than following commands given by others.

Insubordination is a refusal or disobedience in obeying any command, power is the ability to have an influential behavior and courage means bravery to do something without fear.

Therefore, independent actions without instructions are option D. initiative.

Learn more about the initiative here:

brainly.com/question/21106998

#SPJ1

8 0
2 years ago
Other questions:
  • What has prompted schools to add Internet activities in their academic integrity policies?
    6·2 answers
  • Dfd symbols are referenced by using all ____ letters for the symbol name.
    9·1 answer
  • Which word most likely means "a timepiece fitted with a recording device that marks down exact intervals of time"? chronograph c
    9·2 answers
  • You are the senior nurse on the unit and you are orienting a new graduate LVN/LPN. One of the subjects you want to cover today i
    5·1 answer
  • An automotive engine's camshaft rotates at
    8·2 answers
  • WILL GIVE BRAINLIEST AND HALLOWEEN CANDY!!!!!!!!!<br> who wants to talk?
    9·1 answer
  • The students of a college have to create their assignment reports using a word processing program. Some of the questions in thei
    9·1 answer
  • MULTI-SELECT
    9·2 answers
  • An editing functions used to move selected text or objects to the Clipboard, from which they may be pasted elsewhere in the pres
    9·1 answer
  • you are working in the headquarters of an organization and you're asked to deal with the interruption in services due to network
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!