Python Forum
struggling with one part of python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
struggling with one part of python
#1
Hello,

i am struggling to finish the last bit of my script, its for an assessment. I am terrible at scripting unless its for security or penetration.

any ways, i have tried so many things like imp numpy imp panda imp mathamatics, i just cant get it to show the correct data or what not. i am very bad at this time of programming. ive tried so many things and for so long my HEAD hurts. here is my code.

"edit" i just realized it didn't put in the indents when i pasted, oh man i hate programing -.-/


PLEASE HELP MEEEEEEEEEEEEEEE


 
import calendar
print("The calender of year 2020 is : ")
print (calendar.calendar(2020, 2, 1, 6))


import statistics  # for calculation of mean
from decimal import Decimal

all_data = [];
pre_stat_data = {};

april_data = [["1/04/2019", 21.3, 26.8, 0.0], ["2/04/2019", 18.5, 29.0, 0.0], ["3/04/2019", 18.5, 30.0, 0.0]]
may_data = [["1/05/2019", 9.2, 18, 0.0], ["2/05/2019", 5.5, 19.6, 0.0], ["3/05/2019", 6.6, 27.1, 0.0]]
june_data = [["1/06/2019", 7.5, 25.5, 0.0], ["2/06/2019", 5.9, 24.5, 0.0], ["3/06/2019", 7.3, 23.9, 0.0]]
july_data = [["1/07/2019", 11.9, 20.2, 9.4], ["2/07/2019", 6.0, 20.6, 0.2], ["3/07/2019", 6.1, 21.7, 0.0]]

    # create existing data list
for nlist in april_data:
    row = []
for item in nlist:
        row.append(item)  # append item in new list
all_data.append(row)

for nlist in may_data:
    row = []
for item in nlist:
        row.append(item)
all_data.append(row)

for nlist in june_data:
    row = []
for item in nlist:
        row.append(item)
all_data.append(row)
    
for nlist in july_data:
    row = []
for item in nlist:
        row.append(item)
all_data.append(row)

for biglist in all_data:
    the_month_name = ""
    temp_month_dic = {}
for idx, val in enumerate(biglist):
        if (idx == 0):  # date changes
            the_date_arr = val.split('/')
            the_month = int(the_date_arr[1])
            the_month_name = calendar.month_name[the_month]
            # print(the_month_name);
            if the_month_name in pre_stat_data:
                temp_month_dic = pre_stat_data[the_month_name]  # change this number to month
            else:
                pre_stat_data[the_month_name] = temp_month_dic
        elif (idx == 1):  # min temperature
            if "min_temp" in temp_month_dic:
                temp_month_dic["min_temp"].append(val);
            else:
                temp_month_dic["min_temp"] = []
                temp_month_dic["min_temp"].append(val);
        elif (idx == 2):  # max temperature
            if "max_temp" in temp_month_dic:
                temp_month_dic["max_temp"].append(val);
            else:
                temp_month_dic["max_temp"] = []
                temp_month_dic["max_temp"].append(val);
        elif (idx == 3):  # rainfall
            if "rainfall" in temp_month_dic:
                temp_month_dic["rainfall"].append(val);
            else:
                temp_month_dic["rainfall"] = []
                temp_month_dic["rainfall"].append(val);

    # print(pre_stat_data for display)
post_stat_data = {}
for key, value in pre_stat_data.items():
    tempo_temp_list = []
    tempo_temp_list.extend(pre_stat_data[key]["min_temp"])
    tempo_temp_list.extend(pre_stat_data[key]["max_temp"])
    pre_stat_data[key]["temp_list"] = tempo_temp_list;
    pre_stat_data[key]["temp_final_min"] = min(pre_stat_data[key]["min_temp"])
    pre_stat_data[key]["temp_final_max"] = max(pre_stat_data[key]["max_temp"])
    pre_stat_data[key]["temp_final_mean"] = statistics.mean(pre_stat_data[key]["temp_list"])
    pre_stat_data[key]["rain_total"] = sum(pre_stat_data[key]["rainfall"])
    pre_stat_data[key]["rain_min"] = min(pre_stat_data[key]["rainfall"])
    pre_stat_data[key]["rain_max"] = max(pre_stat_data[key]["rainfall"])
    pre_stat_data[key]["rain_mean"] = statistics.mean(pre_stat_data[key]["rainfall"])
    post_stat_data[key] = pre_stat_data[key]
    del post_stat_data[key]["min_temp"]
    del post_stat_data[key]["max_temp"]
    del post_stat_data[key]["temp_list"]
    del post_stat_data[key]["rainfall"]

    # Hard coded data for processing
    post_stat_data = pre_stat_data

    disp_data = {"month_name": [], "temp_min": [], "temp_max": [], "temp_mean": [], "rain_total": [], "rain_min": [],
             "rain_max": [], "rain_mean": []}
for key, value in post_stat_data.items():
    disp_data['month_name'].append(key);
    dec_min = Decimal(post_stat_data[key]["temp_final_min"]);
    dec_min = round(dec_min, 2)  # rounding of decimal
    disp_data['temp_min'].append(dec_min)
    dec_max = Decimal(post_stat_data[key]["temp_final_max"]);
    dec_max = round(dec_max, 2)  # rounding of decimal
    disp_data['temp_max'].append(dec_max)
    dec_mean = Decimal(post_stat_data[key]["temp_final_mean"]);
    dec_mean = round(dec_mean, 2)  # rounding of decimal
    disp_data['temp_mean'].append(dec_mean)
    dec_rain_total = Decimal(post_stat_data[key]["rain_total"]);
    dec_rain_total = round(dec_rain_total, 2)  # rounding of decimal
    disp_data['rain_total'].append(dec_rain_total)
    dec_rain_min = Decimal(post_stat_data[key]["rain_min"]);
    dec_rain_min = round(dec_rain_min, 2)  # rounding of decimal
    disp_data['rain_min'].append(dec_rain_min)
    dec_rain_max = Decimal(post_stat_data[key]["rain_max"]);
    dec_rain_max = round(dec_rain_max, 2)  # rounding of decimal
    disp_data['rain_max'].append(dec_rain_max)
    dec_rain_mean = Decimal(post_stat_data[key]["rain_mean"]);
    dec_rain_mean = round(dec_rain_mean, 2)  # rounding of decimal
    disp_data['rain_mean'].append(dec_rain_mean)

    # display existing data
    print("Existing data table : ")
Reply
#2
Please use proper code tags, it's difficult to understand your code, for your indentation might be your problem
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
i have a link with the text, it has prober indenting etc, please take a look

https://textuploader.com/1cr4p

edit i fixed it i had typed [pyton] ahah.
Reply
#4
I don't understand what's your problem, it's working properly. It's just supposed to show the calendar of 2020 right?
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
what really? when i run it shows calendar and just prints existing data table?. is that all its supposed to do ?

im Terrible at software/business coding, i have nfi what im doing i know syntax and i can copypast scripts and make them work sometimes. unless its a attack tool

what about all the hardcoded data?
Reply
#6
What were you trying to do with the code? I'm confused
You are supposed to know what is your goal, not us.
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#7
(May-08-2020, 10:06 AM)Lucifer Wrote: what really? when i run it shows calendar and just prints existing data table?. is that all its supposed to do ?
how we should now what it is expected to do? It's your code - you tell us what it is supposed to do and how it fails

Also, note that indentation is clearly off than what is intended (e.g. lines 17-40), so it is even harder for us
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
ill get back to you soon, ill review the assessment and get back to you.

i really appreciate your time and help.
Reply
#9
Sure, and this time, explain your full problem to us, so that we can also understand before helping you
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#10
As this is clearly a homework question - I moved it to respective section.
The best would be to post the assignment verbatim
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling on Tuples Mystix 3 4,921 Feb-01-2021, 06:06 PM
Last Post: nilamo
  Struggling with variables pythonstudy00 1 1,501 Sep-23-2020, 06:39 AM
Last Post: DPaul
  Struggling To Understand These 2 Python Files samlee916 2 1,800 Sep-22-2020, 04:50 AM
Last Post: ndc85430
  struggling w/ fonctions in Python Tiril123 7 3,879 May-09-2020, 10:51 AM
Last Post: pyzyx3qwerty
  How to change part of the value string in Python Dictionary? sbabu 11 4,158 Feb-12-2020, 02:25 AM
Last Post: sbabu
  struggling with python save/load function newatpython00 1 2,017 Nov-15-2019, 07:58 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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