Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a program that prints a list with all the items separated by a comma and a space, with and inserted before the last item. For example, the above list would print 'apples, bananas, tofu, and cats'. But your program should be able to work with any list not just the one shown above. Because of this, you will need to use a loop in case the list to print is shorter or longer than the above list. Make sure your program works for all user inputs. For instance, we wouldn't want to print "and" or commas if the list only contains one item. else: 'tofu', You can use the following code to start your program. It will let the user type a list listToPrint = [] while True: newWord = input("Enter a word to add to the list (press return to stop adding words) > ") if newWord == break listToPrint.append(newWord) 'cats'] Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") userChoice = input() if(user Choice == "1"): print("What item do you want to add to the backpack?") itemToAdd = input() #######_YOUR CODE HERE ###### #add the item to the backpack #######_YOUR CODE HERE ###### if(userChoice == "2"): print("What item do you want to check to see if it is in the backpack?") itemToCheck = input() #######_YOUR CODE HERE ###### #Print out if the user's item is in the backpack #######_YOUR CODE HERE ###### if(userChoice == "3"): sys.exit() Comma Code Say you have a list value like this: listToPrint = ['apples', 'bananas' Write a program that prints a list with all the items separated by a comma and a space, with and inserted before the last item. For example, the above list would print 'apples, bananas, tofu, and cats'. But your program should be able to work with any list not just the one shown above. Because of this, you will need to use a loop in case the list to print is shorter or longer than the above list. Make sure your program works for all user inputs. For instance, we wouldn't want to print "and" or commas if the list only contains one item. else: 'tofu', You can use the following code to start your program. It will let the user type a list listToPrint = [] while True: newWord = input("Enter a word to add to the list (press return to stop adding words) > ") if newWord == break listToPrint.append(newWord) 'cats'] Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") Backpack of stuff Complete the following code. Fill in the two sections of code identified in the comments. import sys itemsInBackpack = ["book", "computer", "keys", "travel mug"] while True: print("Would you like to:") print("1. Add an item to the backpack?") print("2. Check if an item is in the backpack?") print("3. Quit") userChoice = input() if(user Choice == "1"): print("What item do you want to add to the backpack?") itemToAdd = input() #######_YOUR CODE HERE ###### #add the item to the backpack #######_YOUR CODE HERE ###### if(userChoice == "2"): print("What item do you want to check to see if it is in the backpack?") itemToCheck = input() #######_YOUR CODE HERE ###### #Print out if the user's item is in the backpack #######_YOUR CODE HERE ###### if(userChoice == "3"): sys.exit()
Expert Answer:
Answer rating: 100% (QA)
1 create an empty list listToPrint loop that inputs words from user and adds it to list until user q... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
4.4 ** A particle of mass m is moving on a frictionless horizontal table and is attached to a massless string, whose other end passes through a hole in the table, where I am holding it. Initially the...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Consider the energy sector consisting of J firms where energy producers are characterized by their cost functions C j (x j ,e j ). The firms are subject to an emission trading system with a total...
-
For the network described in the previous problem, if the potential difference between points a and b is 60.0 V, what charge is stored on C3? Co C2 Go
-
A toy race track has a 1.0-m-long straight section connected to a vertical circular loop-the-loop section of radius 15 cm. The straight section has a uniform magnetic field directed upward of...
-
(a) Consider the flash separation process shown in Figure 7.1. If using ASPEN PLUS, solve all three cases using the MIXER, FLASH2, FSPLIT, and PUMP modules and the RK-SOAVE option set for...
-
a. What type of research should he do? b. Is his IT background sufficient for a case that involves marketing issues? Jason Blair is a CPA who has been asked to serve as an expert witness in a civil...
-
calculates the annual growth rate in expenses or other variables over a multiyear period. puts data on the same relative basis to determine if expenses or other variables are too high or low....
-
All the following case study questions are based on this book: Project management achieving competitive advantage by Jeffrey K. Pinto Question 8.1 1. Given the history of large cost overruns...
-
In a recent 360-degree survey, Sally scored above average (at the 70th percentile) in the competency, Inspires and Motivates Others to High Performance. If you were in a high-ranking managerial...
-
A customer in Halifax purchased a computer and paid $ 2 0 1 . 0 0 in HST ( 1 5 % ) . What was the total cost including HST of the computer purchase?
-
Meteor, Inc. recognized revenue of $ 6 0 0 for the current year, of which $ 1 2 0 was received in cash. The rest of the cash will be collected in the following year. The company incurred expenses of...
-
Worthington Industries sells cookware in France and reports using IFRS. On January 1 , YEAR 0 , Worthington bought a machine to manufacture pans for 2 0 0 , 0 0 0 with a 1 0 year life. Assume that...
-
What are your personal goals related to pursuing your degree: personal fulfillment, finishing something started years ago, good example for your children, advancement at work, etc.? What are your...
-
Mark Wilson resigned from his corporate job on December 1 5 , 2 0 2 1 , to start his sole proprietorship, called Wilson s Consulting. He started on January 1 , 2 0 2 2 . He employed three employees...
-
Explain why were electrons chosen to be negatively charged? Wouldn't it make more sense to call electrons positively charged because when they move they make electricity?
-
Which, if any, of the dichloroethene molecules drawn in Data Table II (3.) (4.) and (5.) are geometric isomers? A. B. C. D. cis-1,2-dichloroethene and trans-1,2-dichloroethene...
-
Clarita is a single taxpayer with two dependent children, ages 10 and 12. Clarita pays $3,000 in qualified child care expenses during the year. If her adjusted gross income (all from wages) for the...
-
Jim is fired from his job as a waiter and decides to take an extended trip to Europe. After touring Europe for 3 months, Jim returns to look for a new job as a waiter. Are his job-hunting expenses...
-
Ken paid the following amounts for interest during 2012: Qualified interest on home mortgage...........................................$4,700 Auto loan...
-
Given forecast errors of 3, 2, -2, and 9, what is the tracking signal?
-
Given a forecast of 2,105 and an actual outcome of 1,980, what is the error in the forecast? What is the percent error?
-
Given an actual demand of 34 this period, a predicted value of 45 this period, and an alpha of 0.2, what would be the simple exponential smoothing forecast for the next period?
Study smarter with the SolutionInn App