Question

For a given list ask user if he/she wants to create a new list that repeats...

For a given list ask user if he/she wants to create a new list that repeats n‐times itself. If Yes‐ create a new list that repeats itself n‐times, (n is user specified).

ask user(use list and while) Python

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

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.



while True:
    # take a list
    lst = [1, 2, 3]

    # print the list
    print('\nThe List is: ', lst)
    # ask user if he wants to create a new list
    choice = input('Do you want to create a new list that repeat itself(yes/ no): ')
    if choice == 'yes':
        # ask how many times?
        n = int(input('How many times you want to repeat? '))
        count = 1
        # take a new list
        repeated_list = []
        # use while loop
        while count <= n:
            # copy the lst n times
            repeated_list.append([num for num in lst])
            count += 1

        # print the repeated list
        print('The list repeated', n, 'times is: ', repeated_list)
    else:
        # User don't want to repeat, so stop
        break

# print a bye message
print('Good Bye!')

=====

OUTPUT

Add a comment
Know the answer?
Add Answer to:
For a given list ask user if he/she wants to create a new list that repeats...
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
  • For a given list ask user if he/she wants to create a new list that repeats...

    For a given list ask user if he/she wants to create a new list that repeats n‐times itself. If Yes‐ create a new list that repeats itself n‐times, (n is user specified). use list python

  • JAVA HELP Create a small program where You ask the user The amount of money he/she...

    JAVA HELP Create a small program where You ask the user The amount of money he/she wants to convert using GUI Pop up input (import javax.swing.JOptionPane;) The first pop up should ask the user to what currency he/she wants to convert, He needs to be able to click that option, The currency you should use are : Euros , Pesos , Yen , Pound , Ruble, Quetzal, Once the user Clicks the option It will ask The amount the user...

  • write a program to ask the user if he or she wants to know about their...

    write a program to ask the user if he or she wants to know about their birth stone. if they do, then display the 12 months and allow user to select the month of thier choice. give them info using their birth stone

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

  • This is a Java text only program. This program will ask if the user wants to...

    This is a Java text only program. This program will ask if the user wants to create a music playlist. If user says he or she would like to create this playlist, then the program should first ask for a name for the playlist and how many songs will be in the playlist. The user should be informed that playlist should have a minimum of 3 songs and a maximum of 10 songs. Next, the program will begin a loop...

  • Problem 1 Write a Python program to do the following: (A) Ask the user to enter...

    Problem 1 Write a Python program to do the following: (A) Ask the user to enter as many integers from 1 to 10 as he/she wants. Store the integers entered by the user in a list. Every time after the user has entered an integer, use a yes/no type question to ask whether he/she wants to enter another one. (B) Display the list. (C) Calculate and display the average of the integers in the list. (D) If the average is...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Solve all using Python 7. Create a list of strings, don't ask from the user, and...

    Solve all using Python 7. Create a list of strings, don't ask from the user, and return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same (use for loop to go through the list). 8. The file State.txt contains the 50 U.S. states in the order in which they joined the union. Write a program to display the original 13 states in...

  • Ask the user for the name of a file. Read a list of numbers of unknown...

    Ask the user for the name of a file. Read a list of numbers of unknown length from the file. Find and print the MEDIAN and the MODE(S) of the set of numbers. Do not use python statistics functions to find the medium or mode To find the MODE(S) Create a dictionary using the numbers as the keys, and the values are how often that number appears in the list. For instance, with this list [1,1,5], the dictionary would be...

  • Write a few lines in Python that will do the following: Create an empty list Ask...

    Write a few lines in Python that will do the following: Create an empty list Ask the user to enter two numbers Add each number to your list

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
ADVERTISEMENT