Write a program that prints a list with all the items

Assignment Help Python Programming
Reference no: EM132181415

Comma Code

Say you have a list value like this:

listToPrint=['apples','bananas','tofu','cats']

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.

You can use the following code to start your program. It will let the user type a list

listToPrint=[]
whileTrue:
newWord= input("Enter a word to add to the list (press return to stop adding words) > ")
ifnewWord=="":
break
else:
listToPrint.append(newWord)

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"]

whileTrue:
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(userChoice=="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()

Character Picture Grid (Extra Credit: Worth 5 additional points)
Say you have a list of lists where each value in the inner lists is a one-character string, like this:

grid=[['.','.','.','.','.','.'],
['.','O','O','.','.','.'],
['O','O','O','O','.','.'],
['O','O','O','O','O','.'],
['.','O','O','O','O','O'],
['O','O','O','O','O','.'],
['O','O','O','O','.','.'],
['.','O','O','.','.','.'],
['.','.','.','.','.','.']]

You can think of grid[x][y] as being the character at the x- and y-coordinates of a "picture" drawn with text characters. The (0, 0) origin will be in the upper-left corner, the x-coordinates increase going right, and the y-coordinates increase going down.

Copy the previous grid value, and write code that uses it to print the image.
..OO.OO..
.OOOOOOO.
.OOOOOOO.
..OOOOO..
...OOO...
....O....

Hint: You will need to use a loop in a loop in order to print grid[0][0], then grid[1][0], then grid[2][0], and so on, up to grid[8][0]. This will finish the first row, so then print a newline. Then your program should print grid[0][1], then grid[1][1], then grid[2][1], and so on. The last thing your program will print is grid[8][5].

Also, remember to pass the end keyword argument to print() if you don't want a newline printed automatically after each print() call. For instance if you wrote:
print("Hello World", end="")
print("Hello")

It would print out the first command without a newline at the end of it:
Hello WorldHello

Attachment:- Python assignment.rar

Verified Expert

In this assignment we have studied and write python programming for complete given assignment. Here we have write the program for looping and create the matrix for pattern design. In this assignment we use different looping structure like while loop and if loop and if else if and write the decision making programme.

Reference no: EM132181415

Questions Cloud

Output growth and inflation are lower than expected : You hear a news report that output growth and inflation are lower than expected. How do you expect that report to affect interest rates? Explain why.
Opening a bank account and depositing : Suppose the target reserve ratio is 0.15. By opening a bank account and depositing $1,000 you will increase deposit $5,000.
What is the overall effect on equilibrium price : The market for gasoline has changed in a couple significant ways over the last few years: new technologies have decreased the costs associated with producing.
What is the minimum cost output for the bagel producer : What is the minimum cost output for this bagel producer? Justify your answer by discussing average total cost and marginal cost.
Write a program that prints a list with all the items : 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
Find the equilibrium price and quantity : 1. The market for Kombucha is represented by the following equations:
Discuss international and multicultural diversity aspects : Provide a fuller picture of the issue by putting it within a context and cite some brief examples or anecdotes about the issue.
What are the aspect of the economics of social media : You will write a brief essay discussing any aspect of the Economics of Social Media in negative way. The essay should be about 1 - 2 pages long and must cite.
Compose an analysis that identifies additional specialists : Compose a 500-750-word analysis that identifies additional specialists and other individuals who should be included as part of the MET team.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd