Python Forum
[PyQt] [Solved]Help Adding results from for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] [Solved]Help Adding results from for loop
#1
Hello,

I'm trying to multiply the Quantity*Price for each row then add them all up to get the total value of all the items I have.

This is what I have so far:
    def calculate_value(self):
        for row in range(self.InventoryDisplay.model().rowCount()):
            QuantityValue = float(self.InventoryDisplay.model().index(row, 2).data())
            PriceValue = float(self.InventoryDisplay.model().index(row, 3).data())
            QuanityPriceValue = QuantityValue*PriceValue
            print(QuanityPriceValue)
My output:
Output:
89.0 0.0 75.0 200.0 32.5 20.0 20.0 4000.0 100.0
The part I'm having trouble with is how do I add all my QuanityPriceValue's that were spit out from that for loop so I can get the combined total (In this case it should be: 4,516.5)?

Thanks in advance.
Reply


Messages In This Thread
[Solved]Help Adding results from for loop - by Extra - Jun-24-2022, 02:08 PM
RE: Help Adding results from for loop - by Extra - Jun-24-2022, 05:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Help getting out of loop Extra 5 4,000 Sep-30-2022, 11:27 PM
Last Post: Extra
  [PyQt] [Solved]Populate ComboBox with for loop? Extra 3 2,275 Jul-31-2022, 09:01 PM
Last Post: Extra
  [PyQt] [Solved]Display PyQtTable results from A->Z & Z->A Extra 2 1,231 Jul-18-2022, 04:04 PM
Last Post: Extra
  [PyQt] [Solved]Help Adding Sql Results in ComboBox Extra 2 1,314 Jul-07-2022, 09:46 PM
Last Post: Extra
  [PyQt] [Solved]Display Search Results in QTable Extra 5 2,593 Jun-29-2022, 10:20 PM
Last Post: Extra

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020