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
Alexus [3.1K]
3 years ago
8

Write a python program that requests a positive integer from the user, determines if it is a composite, a prime or neither prime

or composite and prints the message. You can choose to use iterative loops to repeatedly run this script or have the user run the script for every input.
Computers and Technology
1 answer:
Serjik [45]3 years ago
3 0

Answer:

num = int(input("Num: "))

if num > 1:

    for i in range(2,num):

         if (num % i) == 0:

              print(num,"is a composite number")

              break

         else:

              print(num,"is a prime number")

else:

    print(num,"is neither prime nor composite")

Explanation:

This line prompts user for input

num = int(input("Num: "))

The following if condition check for prime, composite or neither both

if num > 1:

The following iteration checks for prime or composite

    for i in range(2,num):

This if condition tests if a valid divisor can be gotten. If yes, then input number is composite

<em>          if (num % i) == 0: </em>

<em>               print(num,"is a composite number")</em>

<em>           break</em>

<em />

If otherwise, then input number is prime

<em>          else:</em>

<em>               print(num,"is a prime number")</em>

<em />

All numbers less than 2 are neither composite nor prime

else:

    print(num,"is neither prime nor composite")

You might be interested in
In mathematics, "quadrant I" of the cartesian plane is the part of the plane where x and y are both positive. Given a variable,
lbvjy [14]

Answer:

#include <iostream>

using namespace std;

struct Cartesian {

double x;

double y;

};

int main() {

// creating a pointer p of type struct Cartesian

struct Cartesian *p = new Cartesian ;

cout << " Enter x: ";

// accessing the structure variable x by arrow "->"

cin >> p->x;

cout << "Enter y: ";

// accessing the structure variable y by arrow "->"

cin >> p->y;

// expression to check whether x and y lie in Quadrant 1

if (p->x > 0 && p->y > 0) {

 cout << "X and Y are in Quadrant 1 ";

}

else

{

 cout << "x And y are not in Quadrant 1";

}

// deleting the struct pointer p

delete p;

return 0;

}

Explanation:

in order to locate memory in heap, keyword "new" is used in C++ so,

struct Cartesian *p = new Cartesian ;

in order to access data members of the structure using pointer we always use an arrow "->". otherwise a dot oprerator is used to access data members.

in order to check whether x and y lie in 1st quadrent, we must use && operator in our if condition. so

if (p->x > 0 && p->y > 0)

&& will return true iff x and y both are +ve.

deleting the struct pointer p is important beacuse we are allocating memory in heap so heap memory should be used a resource and must be release when not needed otherwise it can cause memory leakage problems. so  

delete p;

5 0
3 years ago
Enumerate the the risk in the preparation and cooking in starch and cereal dishes and other food​
Novay_Z [31]
———————————————————.
6 0
2 years ago
Alonzo collects bugs. He has created a fascinating display of large insects. Collecting bugs is a(n) _____ to Alonzo.
-Dominant- [34]
The answer is hobby. He does it because he enjoys it. There is no information of him being told or paid to collect bugs, so it is a hobby.
3 0
3 years ago
Read 2 more answers
Felicia's Wi-Fi connection to her phone is extremely slow. However, her
Alex Ar [27]

Answer: fake water all across the road

Explanation:

3 0
3 years ago
Read 2 more answers
Which of these devices features D-pads and analog sticks? ASAP PLEASE
Arisa [49]

Answer:

b. portable consoles

Explanation:

hope that helps :)

5 0
3 years ago
Read 2 more answers
Other questions:
  • Give two reasons why it is important to upgrade your browser when a new version becomes available.
    8·1 answer
  • You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?
    10·1 answer
  • Space cushion includes
    8·2 answers
  • What is the way to discover requirments for software projects ?
    14·1 answer
  • Difference between academic library and school Library
    5·1 answer
  • JAVA
    5·1 answer
  • How does the autosum command calculate data? Need help ASAP​
    5·1 answer
  • There is a surplus of scientific researchers for a vaccine. This means the demand for this career has
    8·2 answers
  • after teaching a group of students about measuring systems and drug calculations, the instructor determines that the teaching wa
    15·1 answer
  • if you want to clear a single file, what move instruction would you use? group of answer choices none of the choices file to wor
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!