Solved–Assignment: AG05– Solution

$30.00 $19.00

Primes and Factors Since you are reading this, you have already downloaded and extracted the zip file. 1.1 Tasks to do Open the file a05.py and look between the markers. You may ignore the code outside the markers completely. You may run the code by typing the following from the shell: python a05.py This will…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)
  • Primes and Factors

Since you are reading this, you have already downloaded and extracted the zip file.

1.1 Tasks to do

  1. Open the file a05.py and look between the markers. You may ignore the code outside the markers completely. You may run the code by typing the following from the shell: python a05.py

This will not run the tests but the code itself.

  1. Assumptions and requirements:

    1. You must not use the functions in the math or another library during this assignment. If you break this rule, you risk getting zero score on the whole assignment.

    1. For the whole assignment: A Prime Number can be divided completely (i.e. leaving no remainder) only by 1, or itself. And it must be a whole number greater than 1. 1

    1. For this assignment, you will have to do some searching to solve the whole problem.

  1. There are three main tasks to complete.

    1. Write a function with the name is_prime that takes in one number and decides if that number is prime. It should return a boolean value depending on the decision.

You must use the definition of a prime number given above. Moreover, a real number – which has some value other than 0 in the mantissa (i.e to the right of the decimal point) – is not a prime number. However, if a real number with only 0s in the mantissa is passed, it should be considered as the integer counterpart.2 For instance, 6.0 should be considered as 6 and 5.0 should be considered as 5. However, 6.01 will not be prime and neither will 5.01.

    1. Write another function by the name output_factors. This function should output the factors of the number passed as input – one factor on each line. Factors of a number, say x, are those whole numbers which can be multiplied with other whole numbers to get x.

For instance, if output_factors is given the number 10, it should output the following:

1

2

5

10

  1. The third function that you should define is get_largest_prime. This function will be passed a number and it should return the largest prime number that is smaller than or equal to than this input.

For example, if we pass the number 10 to this function, it should return 7 since 7 is the largest prime that is smaller than 10.

If no prime matching the rules is found, the function should return None.

  • Adapted from: https://www.mathsisfun.com/definitions/prime-number.html

  • If you are stuck on this, look at the hint PDF in the assignment folder. However, it is highly recommended that you try to solve this problem yourself.

CS101 Introduction to Computing (Fall 2017 – Assignment: AG05) Page 1 of 2

1.1 Tasks to do

  1. You may change the values in function calls at the end of the file a05.py to check the functions.

  1. Run local tests and if they pass, submit the assignment using the submission command given on the Autograder assignment page. (Same as the first assignment.)

CS101 Introduction to Computing (Fall 2017 – Assignment: AG05) Page 2 of 2