Question

In: Computer Science

Comments using # and "" "should also be included for reader to understand each part. Question:...

Comments using # and "" "should also be included for reader to understand each part.

Question: 14. Write in python a script code which tells the user to enter an integer bigger than 5. Any input numbers which are smaller than 5 or 5 are not considered by this script. The code then should output all the prime numbers starting at 5, which are smaller than the number inputted by that user.

Solutions

Expert Solution

Code:

# Taking an input from user
number = input("Enter a number greater than 5: ")
# Converting the inputted string to integer datatype
number = int(number)
# If the input number is <=5, display a message and exit the code
if (number<=5):
    print("The input number must be greater than 5.")
    exit
# else find the prime numbers
else:
    # Print statement to convey the information
    print("Prime numbers starting from 5 and smaller than "+ str(number) +" are:")
    # for loop to find the prime numbers between 5 and the input number
    for num in range (5, number):
        count = 0
        # checking the divisors of the number
        for i in range(2, (num//2 + 1)):
            if(num % i == 0):
                count = count + 1
                break
        # if divisors are zero, then print the number
        if (count == 0):
            print(" %d" %num, end = '  ')

Screenshot for better understanding:

Output examples:

Using the input() we take user input and then check whether it satisfies our condiiton. If it does, we find all the prime numbers in that range using the for loop. The first for loop traverses the numbers in range, while the second counts number of divisors of that number except 1 and itslef. If the count of divisors comes out to be zero, that means it is prime and we print it.


Related Solutions

#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
please I don't understand this code. Can you put comments to explain the statements. Also, if...
please I don't understand this code. Can you put comments to explain the statements. Also, if there any way to rewrite this code to make it easier, that gonna help me a lot. import java.io.*; import java.util.*; public class State {    private int citi1x,citi1y; private int pop1; private int citi2x,citi2y; private int pop2; private int citi3x,citi3y; private int pop3; private int citi4x,citi4y; private int pop4; private int plantx,planty; public int getCity1X(){ return citi1x; } public int getCity1Y(){ return citi1y;...
Answering the experts question in the comments below i included a weblink that does not redirect...
Answering the experts question in the comments below i included a weblink that does not redirect you directly to the article as when I post it direct it gives an error message. So, once you go to the link I have provided below you will have to click on the third article titled: Distinction between Emotion and Mood. http://ivizlab.sfu.ca/arya/Papers/Others/Emotions/hl_index.html ANSWER THE FOLLOWING QUESTIONS: 1. The purpose of the article or problem statement 2. A brief summary of the literature review...
Which of the following should NOT be included as part of manufacturing overhead at a company...
Which of the following should NOT be included as part of manufacturing overhead at a company that makes office furniture? [[selectone]] a. Idle time for direct labor. b. Sheet steel in a file cabinet made by the company. c. Manufacturing equipment depreciation. d. Taxes on a factory building.
Write an evidence-based response to each question below. ● Determine what should be included in client...
Write an evidence-based response to each question below. ● Determine what should be included in client and family teaching that reflects principles associated with the following. ○ Informed consent ○ Refusal of treatment ○ Advance directives
The first part of the question was answered and I was able to understand it, but...
The first part of the question was answered and I was able to understand it, but the second part of it was answered. Can you explain this part to me. Calculate the amount to be recorded for each item in the table below and enter the value in the associated cell. Round all numbers to the nearest whole number. Item Amount Building Leased equipment Land received from Club on Link's books Land received from Link on Club's books QUESTION 22...
1. Answer three parts of the question. Your answer for each part should be no more...
1. Answer three parts of the question. Your answer for each part should be no more than two pages long. (a) Describe how a Collateralized Debt Obligation (CDO) distributes payments to its investors. (b) ‘American call options should never be exercised before the maturity date’. Evaluate this statement, providing proofs where necessary. (c) Explain how you would create a Box spread and show its payoff at maturity. (d) Holding all other factors constant, what effect does a change in the...
1. Answer three parts of this question. Your answers for each part should be no more...
1. Answer three parts of this question. Your answers for each part should be no more than two pages long. a. Describe the assumed process for the evolution of the underlying asset price in the Black-Scholes optionpricing model. b. Derive the lower bound for a European put option written on a non-dividend paying stock and explain how you could make a riskless profit if this bound is violated. c. ‘American call options written on non-dividend paying stocks should never be...
In what situation should short-term debt or notes payable be included as part of the cost...
In what situation should short-term debt or notes payable be included as part of the cost of debt when calculating the WACC?
An example of a PICO and define each component (the same information should be included in...
An example of a PICO and define each component (the same information should be included in both the listing below as well as the sentence/question) Population- Intervention- Compared to- Outcome- Time (If appropriate)-
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT