Question

Create a loop that will populate a listbox with random values                                 &

  1. Create a loop that will populate a listbox with random values                                     14 pts
    1. The random numbers should range for ranging from 0 to 10 (10 must be a potential number that will be added).
    2. Keep adding values to the listbox until the sum of the values in the listbox equals or exceeds 100.
    3. After adding the values, tell me how many items are in the listbox, and the sum of the numbers, displaying these values in labels.
  2. Create a loop that will populate a listbox with random values                                     14 pts
    1. The random numbers should range for ranging from 0 to 10 (10 must be a potential number that will be added).
    2. Before adding the random number to the listbox, check to see if doing so would make the sum of the number exceed 100. If adding the number would cause the sum to exceed 100, do not add the number, and stop the loop. DON’T insert the number if it would make your sum exceed 100.
    3. Report the current sum of the numbers, and the random number you just picked that would push the sum over 100. Put these values in labels.

Let the user enter a limit value .Create a loop that will calculate powers of 2 (i.e., 1, 2, 4, 8, 16 …) and place them into the listbox. You should stop the loop as soon as the calculated power of 2 exceeds the user’s limit value. If the user entered 10, you would end up with 1, 2, 4, 8,
and then stop. If the user entered 16, you would end up with 1, 2, 4, 8, 16 in the listbox
and stop.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As understood, there are three questions. Let's tackle them one by one. Since no language is specified, general algorithm based style will be used to explain.

ANSWER 1

NOTE : The list is needed to be dynamic because the size of the list is not known. For this purpose, linked ist in C can be used, JAVA has ArrayList and python has built-in list data structure. Nevertheless, it is assumed that we have a readymade data sturucture like that in JAVA or python.

Algorithm:

1. Initialise the empty list L, and a variable to store sum, Sum=0.

2. Generate a random number and take it's modulus 11, say the result is R and add it to the Sum and append it to the list L.

3. If Sum is less than 100, repeat step 2, else continue to step 4.

4. Print all the values one by one from the starting of the list.

Python Code :

ANSWER 2:

This question also needs dynamic lists.

Algorithm:

1. Initialise the empty list L, and a variable to store sum, Sum=0.

2. Generate a random number and take it's modulus 11, say the result is R.

3. If Sum+R is less than 100, add R to the Sum and append R to the list then repeat step 2, else continue to step 4.

4. Print Sum and R value and stop.

Python Code;

ANSWER 3:

This question can be done without dynamic list, by finding out the number of elements required beforehand. But here solution is given considering dynamic list.

Algorithm:

1. Take user input in a variable Inp.

2. Initialize variable Cnt from 1.

3. If Inp is less than Cnt, stop here else continue to step 4.

4. Add Cnt to list L and multiply Cnt by 2.

5. Check if Cnt is less than or equal to Inp. If yes then repeat step 4 else go to Step 6.

6. Print all the values of L starting from the first one.

Python Code:

Add a comment
Know the answer?
Add Answer to:
Create a loop that will populate a listbox with random values                                 &
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

  • 1. Create List 2. Create Random integers 3. Search List Write a program that gets random...

    1. Create List 2. Create Random integers 3. Search List Write a program that gets random integers and populates a list, then searches the list 1. Write a program that creates an empty list 2. Populate the list with 100 random integers 3. After creating the list, print the length of elements in the list 4. Select a range of numbers as 10 – 20 5. Find out the number of times ‘15’ appears in the list and print it...

  • Labview question: Create a VI using a While Loop that continuously generates random numbers between 0...

    Labview question: Create a VI using a While Loop that continuously generates random numbers between 0 and 1000 until it generates a number that matches a number selected by the user. Determine how many random numbers the VI generated before the matching number. conditions to applied on above problem: 1. Convert the “random number” generator floating point numerical output to integer values to make it easier to find a match. 2. The “user selected number control” should be on the...

  • C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating...

    C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating it's values. Then, we'll use the values in the array to calculate the average. Since it's common for an average to result in numbers with decimal points, the array you create should be of type double[]. This program will need to use dynamic input from the user so perform the following steps: Ask the user how many numbers need to be added. Use this...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5...

    Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5 digits. Of those numbers give me the following information: - Mean , Mode, Median, Range. - Five times, ask the user for a number within the range (from above) and record the time to find the number in the range. (Loop count) 2. Using a any sort algorithm, build sorted 2D array of random numbers (1 TO 5 digits ) with the x direction...

  • Must be done in python and using linux mint Write a program to create a text...

    Must be done in python and using linux mint Write a program to create a text file which contains a sequence of test scores. Each score will be between 0 and 100 inclusive. There will be one value per line, with no additional text in the file. Stop adding information to the file when the user enters -1 The program will first ask for a file name and then the scores. Use a sentinel of -1 to indicate the user...

  • Please write the following 4 programs in Java. [Programs completed but with errors, could someone re-create...

    Please write the following 4 programs in Java. [Programs completed but with errors, could someone re-create it?] Please make it as simple as possible. [I am a beginner] 1. How would you use random numbers to represent the drawing of a playing card? Write a loop to test your answer by generating 100 randomly drawn cards and verify that they are in the correct range by printing and looking them over. 2. How would you use random numbers to represent...

  • I must create a Loop in C++ that will print all prime numbers less than the...

    I must create a Loop in C++ that will print all prime numbers less than the number entertered by the user. 1. Accept the upper limit from the user (as an integer). (5 points) 2. Make sure the number is positive. If it is not, terminate the program. (5 points). 3. Go from 1 to the number. If you happen to find a number that is prime, print it. (35 points) example: Enter the upper limit: 25 The prime numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT