Sep-08-2021, 10:16 AM
(This post was last modified: Sep-08-2021, 01:19 PM by Roman_Y.
Edit Reason: Added code tags
)
# Dear Python experts please help me with the task.
_______________________________________________________________
# There're four lines:
# delta_history containing 'product names', 'prices delta'(for example: price from Feruary minus price from January = february_price_delta)
# january_price_list containing January products prices in JSON format
# february_price_list containing February products prices in JSON format
# march_price_list containing March products prices in JSON format
# We have to count the deltas between the prices and put them into delta_history using Python with no importing
# external modules. In case of error (no December prices) we have to see "No Data".
# Important prerequisite: the code should work for any quantity of items in.
# Important note: the number of delta_history list will come from the quantity of indexes in prices.
# How to resolve the task using cycles?
I broke at the beginning on:
_______________________________________________________________
delta_history = [ ['apple', ['january_price_delta', 'february_price_delta', 'march_price_delta']], ['orange', ['january_price_delta', 'february_price_delta', 'march_price_delta']] ] january_price_list = [{'product': 'apple', 'price': '100'}, {'product': 'orange', 'price': '200'}] february_price_list = [{'product': 'apple', 'price': '105'}, {'product': 'orange', 'price': '210'}] march_price_list = [{'product': 'apple', 'price': '110'}, {'product': 'orange', 'price': '215'}]_______________________________________________________________
# There're four lines:
# delta_history containing 'product names', 'prices delta'(for example: price from Feruary minus price from January = february_price_delta)
# january_price_list containing January products prices in JSON format
# february_price_list containing February products prices in JSON format
# march_price_list containing March products prices in JSON format
# We have to count the deltas between the prices and put them into delta_history using Python with no importing
# external modules. In case of error (no December prices) we have to see "No Data".
# Important prerequisite: the code should work for any quantity of items in.
# Important note: the number of delta_history list will come from the quantity of indexes in prices.
# How to resolve the task using cycles?

I broke at the beginning on:
for i in delta_history: a = january_price_list[i] # How to put here a reference to the same index in january_price_list as the "i" is. print(a)________________________________________

Error:Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users//AppData/Roaming/JetBrains/PyCharmCE2021.2/scratches/temp2.py", line 11, in <module>
a = january_price_list[i]
TypeError: list indices must be integers or slices, not list
Yoriz write Sep-08-2021, 10:59 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Homework and No Effort Questions
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Homework and No Effort Questions