Write a function to return all the prime numbers less than n, where n is a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function to return all the prime numbers less than n, where n is a parameter (assumen > 2). $ primes (40) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] ]: def primes (n): """Returns all prime numbers from 2 to n (excluding n) """ # YOUR CODE HERE raise Not ImplementedError() Write a function to return all the prime factors of n, where n is a parameter (Hint: you can call your prime function from the previous problem). $ factor (40) [2, 2, 2, 5] $ factor (23) [23] def factor (n): """""Return all the prime factors of n.""" #YOUR CODE HERE raise NotImplementedError() Write a function called increasing_digits to count all integers from 1 to n (inclusive) that have all digits in increasing order, where n is given as a parameter. For example, • 5 is in increasing order (single digit) • 237 is in increasing order (2 < 3 < 7) .227 is not (22) • 427 is not (4 * 2) . [In]: increasing_digits (30) [Out]: 24 1: def increasing_digits(n): *** Returns the number of integers from 1 to $n$ (inclusive) that have all digits in increasing order, where $n$ is given as a parameter. www # YOUR CODE HERE raise NotImplementedError() Write a function called stats to return the mean, median, and standard deviation (in that order) of a list of integers, where the list of integers is given as a parameter. x₁ Suppose the numbers are x₁,x2,...,x. Then the mean is μ = The median is the "middle" value is the number of integers (n) is odd, or the average of the two "middle" values if it is even (assuming the x, values are arranged in increasing order). The standard deviation is computed as follows: 11(x₁ -μ)². The stats must be returned in a list. Example: [In]: stats([15, 4, 10, 21) [Out]: [7.75, 7.0, 5.909032633745278] : import math ]: def stats(ints): www Returns the mean, median, and standard deviation (in that order) of a List of integers given as a parameter. www # YOUR CODE HERE raise Not ImplementedError() Write a function called zero_triples to return all triples in a list of integers that sum to zero. You can assume the list won't contain any duplicates, and a triple should not use the same number more than once. [In]: zero triples ( [1, 2, 4]) [Out]: [] [In]: zero_triples ( [-3, 1, 4, 21) [Out]: [[1, 2, -311 [In]: zero_triples ([-9, 1, -3, 2, 4, 5, -4, -1]) [Out]: [[-9, 4, 51, [1, -3, 2], [-3, 4, -1], [5, -4, -1]] def zero_triples (ints): Returns all triples in a list of integers that sum to zero. The list of integers is given as a parameter. Assumes the list will not contain any duplicates, and a triple should not use the same number more than once. www *** # YOUR CODE HERE raise NotImplementedError() Write a function to return all the prime numbers less than n, where n is a parameter (assumen > 2). $ primes (40) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] ]: def primes (n): """Returns all prime numbers from 2 to n (excluding n) """ # YOUR CODE HERE raise Not ImplementedError() Write a function to return all the prime factors of n, where n is a parameter (Hint: you can call your prime function from the previous problem). $ factor (40) [2, 2, 2, 5] $ factor (23) [23] def factor (n): """""Return all the prime factors of n.""" #YOUR CODE HERE raise NotImplementedError() Write a function called increasing_digits to count all integers from 1 to n (inclusive) that have all digits in increasing order, where n is given as a parameter. For example, • 5 is in increasing order (single digit) • 237 is in increasing order (2 < 3 < 7) .227 is not (22) • 427 is not (4 * 2) . [In]: increasing_digits (30) [Out]: 24 1: def increasing_digits(n): *** Returns the number of integers from 1 to $n$ (inclusive) that have all digits in increasing order, where $n$ is given as a parameter. www # YOUR CODE HERE raise NotImplementedError() Write a function called stats to return the mean, median, and standard deviation (in that order) of a list of integers, where the list of integers is given as a parameter. x₁ Suppose the numbers are x₁,x2,...,x. Then the mean is μ = The median is the "middle" value is the number of integers (n) is odd, or the average of the two "middle" values if it is even (assuming the x, values are arranged in increasing order). The standard deviation is computed as follows: 11(x₁ -μ)². The stats must be returned in a list. Example: [In]: stats([15, 4, 10, 21) [Out]: [7.75, 7.0, 5.909032633745278] : import math ]: def stats(ints): www Returns the mean, median, and standard deviation (in that order) of a List of integers given as a parameter. www # YOUR CODE HERE raise Not ImplementedError() Write a function called zero_triples to return all triples in a list of integers that sum to zero. You can assume the list won't contain any duplicates, and a triple should not use the same number more than once. [In]: zero triples ( [1, 2, 4]) [Out]: [] [In]: zero_triples ( [-3, 1, 4, 21) [Out]: [[1, 2, -311 [In]: zero_triples ([-9, 1, -3, 2, 4, 5, -4, -1]) [Out]: [[-9, 4, 51, [1, -3, 2], [-3, 4, -1], [5, -4, -1]] def zero_triples (ints): Returns all triples in a list of integers that sum to zero. The list of integers is given as a parameter. Assumes the list will not contain any duplicates, and a triple should not use the same number more than once. www *** # YOUR CODE HERE raise NotImplementedError()
Expert Answer:
Answer rating: 100% (QA)
Note The given code does not have indentation So you can check in images of code that has indentation The images that are provided has code and output of the code Here is the Python code for each ques... View the full answer
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date:
Students also viewed these programming questions
-
As an incentive for farmers, Canadian government sets a guaranteed price which is higher than the market-determined price for food products (price floor). Can you explain with the aid of a diagram...
-
Listing 5.15 determines whether a number n is prime by checking whether 2, 3, 4, 5, 6, ..., n/2 is a divisor. If a divisor is found, n is not prime. A more efficient approach is to check whether any...
-
A prime number is a number that is evenly divisible only by 1 and itself. The prime numbers less than 100 are listed below. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97...
-
9. A molybdenum-vanadium alloy of composition 50wt%Mo - 50wt%V is slowly cooled from a temperature of 2600C to 1800C. Determine: a) At what temperature does the first solid phase form? b) What is the...
-
What three features of Mach make it appropriate for distributed processing?
-
International CAPM. What are the fundamental distinctions that the international CAPM tries to capture which traditional domestic CAPM does not?
-
A petrol engine with compression ratio of 5 develops \(20 \mathrm{~kW}\) indicated power and consumes 8 litres of fuel per hour. The specific gravity of fuel is 0.78 and its calorific value is \(44...
-
In fiscal 2017, Ruthilda Inc. (Ruthilda) decided to exercise its option to redeem its outstanding bond issue before the maturity date in 2024. The bonds had a face value of $6,000,000 and Ruthilda...
-
determine the superficial gas velocity VSG at each transition using the correlations provided Water superficial velocity (m/s) Water density (kg/m) Gas density (kg/m) Fluid's properties [0.001-10]...
-
# EDGAR - Reading Information Tables in Text Format - Advanced Text Mining # Do not use Beautiful Soup or any other parser for this assignment. Do not use NumPy or Pandas as well. #### So far, we...
-
6) Four resistors are connected as shown. R1 and R2 are of the same value and R3 and R4 are of the same value. R1 is half the value of R4 and R2 is half the value of R3. Req of the network is 666.67...
-
List down information that a lender examines when assessing a borrower's capacity. Explain the importance of cash flow in determining creditworthiness.
-
An equation of line is 3y - 6x = 12 a) Sketch the this equation by usinf the following method: - x and y intercepts - Table of values - Slope intercept form 2- A company produces hats, use the market...
-
The daily low temperatures, in degrees Fahrenheit, for 9 consecutive summer days in a city, were 55, 56, 65, 68, 59, 53, 58, 65, and 61. What was the average low temperature for those 9 days
-
Describe the banking industries main competitors? Describe how they contribute to banking system. Why they contribute to banking system. Discuss critically with examples.
-
Definition and Analyse the roles of the gearing ration and the risk-assets ration in banking regulation. Give the example
-
5. Problem 3.3.25. Suppose that instead of a straight line, we fit the data in Problem 24 (i.e #3 above) by a parabola y = C + Dt + Et. In the inconsistent system AF = 6 that comes from the four...
-
Explain the Hawthorne effect.
-
Use the Caesar cipher to encrypt the plaintext: "All Gaul is divided into three parts."
-
For p a prime, let be irreducible of degree n in Zp[x]. (a) How many elements are there in the field Zp [x]/(s(x))? (b) How many elements in Zp[x]/(s(x)) generate the multiplicative group of nonzero...
-
Let m, n Z+ with m n 2. (a) Determine how many distinct cycles of length 4 there are in Km,n. (b) How many different paths of length 2 are there in Km,n ? (c) How many different paths of length 3...
-
Figure P32.94 shows, for an AC circuit, the instantaneous current through a circuit element and the potential difference across the element. What can you determine about the element? Data from Figure...
-
The circuit in Figure P32.96 represents your planned design for a wall power supply that will run a radio that usually runs on a 9-V battery. The power supply uses a transformer (not shown) to...
-
Your boss has purchased a new AC power source to run a high-voltage, low-current display, but it is not working. While he is fuming, you look at the owner's manual and discover that this power source...
Study smarter with the SolutionInn App