Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python programming you should use While loop For loop Range() Break Continue A Fluky Number is a number that is equal to the sum of

python programming

you should use

  • While loop
  • For loop
  • Range()
  • Break
  • Continue

A Fluky Number is a number that is equal to the sum of a set of random numbers, where the random numbers are the first random numbers generated after seeding a random number generator with each factor of the number, not including itself. That's quite a mouthful, so here it is again in simpler terms. All of the following requirements must be met for a number to be a Fluky Number.

  1. A Fluky Number is a number, called The Number, that is equal to the sum of a set of randomly generated numbers.
  2. Random numbers are generated with a random number function. We will use randint() from the random module.
  3. The randomly generated numbers are in the range of 1 to the The Number, inclusive. (Ex. If The Number is 10, the random number can be 1 through 10, including 1 and 10)
  4. Random numbers are the first number generated after setting a specific seed value (Use the random.seed() function).
  5. The seed values are all of the factors of The Number, not including itself. (Ex. The factors of the number 10 that will be used for the seed are 1, 2, and 5)

You must write a program to find all Fluky Numbers from 1 to 10000. As a tip to help make sure you're on the right track, the first 3 Fluky Numbers are: 8, 22, and 25. Your program must discover these numbers, you may NOT use code such as the following:

if testNum == 8: print("Found a Fluky Number!")

You may know that there are 7 Fluky numbers between 1 and 10000.

Your program must print the total running time in seconds to two decimal places. It must print the total number of inner loops executed. Here is an example output, without actual numbers showing: (Note: An 'X' does not indicate the number of digits or any other meaning. It's just a filler)

Fluky Number: 8 Fluky Number: 22 Fluky Number: 25 Fluky Number: XX Fluky Number: XX Fluky Number: XX Fluky Number: XX Total Time: XX.XX seconds Total Loops: XXXXXXXXXXX

See Rubric for all requirements. Make sure to catch the points for reducing the number of required loops.

NOTE: Your code must discover all seven Fluky Numbers using a nested loop structure. You cannot use any information about the properties of Fluky Numbers other than what is described. Your program may know that there will be exactly seven Fluky Numbers numbers with values of 10,000 or less. You may use basic math/logic principles to help you reduce the number of iterations. If you're reading through Wikipedia or doing google searches then you are over-thinking it. Think through in your planning how you can reduce the number of iterations without affecting the results...and think simply.

Find the 7 Fluky Numbers Properly

under 2,000,000 loops

Print total number of iterations inner loop

Print total running time message

print in seconds with two decimal places

The instructions above are NOT what I need help with. I've already done the assignment. Here is a copy of my code:

image text in transcribedimage text in transcribed

The thing I'm having trouble with is creating a software development plan for this code. If someone could help me out with this I'd appreciate it.

Dimport random Aimport time # start measuring time start = time.time() # to store number of iterations iterations = 0 # starting from 2 n =2 while True: from math import sqrt # incrementing number of iterations iterations += 1 # to store sum of the random numbers sum = 0 # going from 1 to sqrt(n) for i in range(1, int(sqrt(n)) + 1): # incrementing number of iterations iterations += 1 # for i = 1, it also counts for n, So We ignore 1 if i == 1: continue # finding factors, seeding the generator # generating and adding the first number if n % i == 0: if n // i == i: random.seed (i) sum += random.randint(1, n) else: random.seed(i) sum += random.randint(1, n) random.seed(n // i) sum += random.randint(1, n) # seeding the generator for 1 and # generating and adding the first number random.seed (1) sum += random.randint(1, n) # if sum is equal to n if sum == n: # output print('Fluky Number:', n) # incrementing number n += 1 # condition to stop the loop if n > 10000: A break # end measuring time end = time.time() # output print("Total Time: %.2f seconds" % (end - start)) print("Total Loops:", iterations)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

wHat are tHe cHallenGes of international is manaGement? Appendix

Answered: 1 week ago

Question

5. Describe how contexts affect listening

Answered: 1 week ago