Question

In: Computer Science

This is for Python programming, and I am trying to use 2 for loops to ask...

This is for Python programming, and I am trying to use 2 for loops to ask a slaesperson how many of 5 different items they sold, then the program is to calculate the total dollar amount sold. Formatting and all that aside, I am having an issue with the loops not stepping through the 2 lists at the same time. The first loop is taking all 5 entered quantities times the price of the first item, and then all 5 quantities times the price of the 2nd item, etc. I need to get Item1 * Quant1, Item2 * Quant2, etc.

Item1 = 2.5
Item2 = 1.98
Item3 = 5.75
Item4 = 3.45
Item5 = 4.0
  
Quant1 = int(input("Enter the quantity of Item1 sold: "))
Quant2 = int(input("Enter the quantity of Item2 sold: "))
Quant3 = int(input("Enter the quantity of Item3 sold: "))
Quant4 = int(input("Enter the quantity of Item4 sold: "))
Quant5 = int(input("Enter the quantity of Item5 sold: "))
for Item in [Item1, Item2, Item3, Item4, Item5]:
for Quant in [Quant1, Quant2, Quant3, Quant4, Quant5]:
Cost = float(Quant * Item)
print (Cost)

Solutions

Expert Solution

Python 3 code

============================================================================================

Item1 = 2.5
Item2 = 1.98
Item3 = 5.75
Item4 = 3.45
Item5 = 4.0
  
Quant1 = int(input("Enter the quantity of Item1 sold: "))
Quant2 = int(input("Enter the quantity of Item2 sold: "))
Quant3 = int(input("Enter the quantity of Item3 sold: "))
Quant4 = int(input("Enter the quantity of Item4 sold: "))
Quant5 = int(input("Enter the quantity of Item5 sold: "))

total=0
for Item,Quant in zip([Item1, Item2, Item3, Item4, Item5],[Quant1, Quant2, Quant3, Quant4, Quant5]):
Cost=float(Quant * Item)
total=total+Cost
print(Cost)

print('total cost is: ',total)
  

============================================================================================

Output


Related Solutions

In C programming, I am trying to search for the names of people that in this...
In C programming, I am trying to search for the names of people that in this DOISigned.txt file, however I am having trouble getting the first and last names of the multiple people named john, my current code only searches for John once and then it terminates,here is my current code #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUF_SIZE 0x3000 char buf[BUF_SIZE]; int main() {    char* inputFile = "DOISigners.txt";    FILE* fp;    fp = fopen(inputFile, "r");...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 2? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 3? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
this is my code in python I am trying to open a file and then print...
this is my code in python I am trying to open a file and then print the contents on my console but when i run it nothing prints in the console def file_to_dictionary(rosterFile): myDictionary={}    with open(rosterFile,'r') as f: for line in f: myDictionary.append(line.strip()) print(myDictionary)             return myDictionary    file_to_dictionary((f"../data/Roster.txt"))      
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX...
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX INPUT: B C D A OUTPUT: D C B A #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]) {         int MAX = 100000;         int i =0;         int k =0;         int j =0;         char array[MAX];         char split[] = " ,.-!?()0123456789";         int n = 0;         char second[MAX];         printf("Please enter in a String: ");...
In the given instruction, I am to use while loops only. The goal is to prompt...
In the given instruction, I am to use while loops only. The goal is to prompt the user to select an acceptable input. If the wrong input is given, the program forces the user to select an appropriate input. The program also keeps running until the user chooses to exist by selecting a very specific input which in my case is the upper or lower case "E". The problem is even after selecting upper or lower case "E", my program...
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
I am trying to make a Risk Management tool in Python. I have it partially started....
I am trying to make a Risk Management tool in Python. I have it partially started. The scenario is that the Project Manager needs to be able to log on and enter information ( the required information is located in the code). I then need to capture that data and store it in an array with the ability to call back and make changes if necessary. Could you please help me out and explain what was done? Current code: Start...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line...
Using Python, I am trying to integrate 'iloc' into the line of code below? This line is replacing all the '1' values across my .csv file and is throwing off my data aggregation. How would I implement 'iloc' so that this line of code only changes the '1's integers in my 'RIC' column? patient_data_df= patient_data_df.replace(to_replace=[1], value ="Stroke") Thank you:)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT