Question

In: Computer Science

Python 1. A salesman can sell five different items. Write a program that lets the salesman...

Python

1. A salesman can sell five different items. Write a program that lets the salesman enter the quantity of each item sold, calculates the total sales, and prints as below. Use a for loop to ask the salesman how many of each product he sold.

tem 1 $2.50

Item 2 $1.98

Item 3 $5.75

Item 4 $3.45

Item 5 $4.00

2. Rewrite program #1 using a for loop to run for 3 salesmen and print the total sales for each

salesman as below.

3. Rewrite program #2 to let the salesman determine when he/she is finished entering the

item/quantity.

Solutions

Expert Solution

1.

CODE

prices = []

quantity = []

for i in range(1, 6):

quantity.append(int(input("Quantity sold for item %d? " %i)))

prices.append(float(input("Price of item %d? " %i)))

for i in range(5):

totalCost = prices[i] * quantity[i]

print("Item %d $%.2f" %(i+1, totalCost))

2.

CODE

for j in range(1, 4):

print("Enter details of Salesperson %d" %(j))

prices = []

quantity = []

for i in range(1, 6):

quantity.append(int(input("Quantity sold for item %d? " %i)))

prices.append(float(input("Price of item %d? " %i)))

for i in range(5):

totalCost = prices[i] * quantity[i]

print("Item %d $%.2f" %(i+1, totalCost))

3.

CODE

for j in range(1, 4):

print("Enter details of Salesperson %d" %(j))

prices = []

quantity = []

i = 1

while(True):

quantity.append(int(input("Quantity sold for item %d? " %i)))

prices.append(float(input("Price of item %d? " %i)))

i += 1

cont = input("Do you wish to continue? (yes/no) : ")

if cont.lower() == "no":

break;

for i in range(len(quantity)):

totalCost = prices[i] * quantity[i]

print("Item %d $%.2f" %(i+1, totalCost))


Related Solutions

IN JAVA A salesman wants to go to five different cities and sell some products. The...
IN JAVA A salesman wants to go to five different cities and sell some products. The locations of the cities are listed in the following table. City # X_location Y_location City 1 1 1 City 2 1 3 City 3 4 1 City 4 5 3 City 5 3 5 The distance between two cities is defined as the Euclidean distance. That is: Distance = sqrt( (x1 – x2)^2 + (y1 – y2)^2 ) For example, the distance between cities...
using python3 Write a Python program that lets a user search through the 'data.txt' file for...
using python3 Write a Python program that lets a user search through the 'data.txt' file for a given first name, last name, or email address, and print all the matches/results. Prompt the user for which field to search, (f) for first name, (l) for last name, or (e) for email data.txt entries are all formatted as: first_name, last_name, email, separated by TABS Your program should not read the entire file into memory, it should read line by line, and only...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program should begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive. Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are...
Write a Python program to manage league matches. Different teams can participate in a league. A...
Write a Python program to manage league matches. Different teams can participate in a league. A player belongs to a team and a team can play many games in a league. For each team, the league wants to track the name of the team and the number of players in each team. The league also wants to track the number of games the team has played, and the total numbers of points scored across all games played. During each game,...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i used random.randint(1,1000) -must give hints like (pick a lower/higher number) which i already did -tell the user when he has repeated a number (help) -the game only ends when you guess the number (help) -you loose $50 every failed attempt (done) ****I did it as a while loop -
FOR PYTHON: Write a python program for a car salesperson who works a five day week....
FOR PYTHON: Write a python program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown...
Write a Python program to count occurrences of items (and retrieve the most 3 or least...
Write a Python program to count occurrences of items (and retrieve the most 3 or least 3 words). Write a Python program to sort a dictionary by keys or values in ascending or descending order by 2 methods.
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that...
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that asks for the name of the item and the price of each item, and then displays these on the screen. Refer to the print() and input() statements covered in the module. Do NOT use loops as it will be covered in later modules. Apples 2.10 Hamburger 3.25 Milk 3.49 Sugar 1.99 Bread 1.76 Deli Turkey 7.99 Pickles 3.42 Butter 2.79
A customer comes into a grocery store and buys 8 items.   Write a PYTHON program that...
A customer comes into a grocery store and buys 8 items.   Write a PYTHON program that prompts the user for the name of the item AND the price of each item, and then simply displays whatever the user typed in on the screen nicely formatted.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT