Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please don't use panda and as I am in the intro class, I can't really write any fancy code. In addition, I did my own

image text in transcribedimage text in transcribed

Please don't use panda and as I am in the intro class, I can't really write any fancy code.

In addition, I did my own to solve this problem but the program said: ValueError: invalid literal for int() with base 10: 'Year'

can you fix this for me? Thank you

my code:

ideal_high_temp = 70 ideal_low_temp = 50 ideal_humidity = 56 ideal_mean_temp = (ideal_high_temp + ideal_low_temp) / 2 ideal_weather = [ideal_high_temp, ideal_low_temp, ideal_mean_temp, ideal_humidity]

years = [] distances = []

NOLAFILE = "nola_weather_feb.csv"

with open(NOLAFILE, "r") as file: for line in file: year, high, low, mean, humidity = line.strip().split(",") year = int(year) high = int(high) low = int(low) mean = (high + low) / 2 humidity = humidity weather_data = [high, low, mean, humidity] distance = 0 for i in range(len(ideal_weather)): distance += (ideal_weather[i] - weather_data[i]) ** 2 distance = distance ** 0.5 years.append(year) distances.append(distance)

# find the year with the smallest distance and its corresponding distance min_distance_year = years[distances.index(min(distances))] min_distance = min(distances)

# print the result print(f"The year closest to your ideal weather is {min_distance_year} with distance {min_distance:.2f}")

Filename: nola_v2.py Input files: nola weather feb. csv, same as for the previous problem Remember the Euclidean distance computation we used back in HW2? Back then, we computed the distance between two locations in physical space. Data scientists use distance measures for all kinds of things, not just physical distance, and for this problem we'll use it to compare days based on the weather. Given an ideal weather forecast, we'll find the year that was the closest to that ideal. First, prompt the user for their ideal weather conditions: ideal high temp, low temp, and humidity. Compute the mean from their high and low. Create a list with their ideal high_temp,llow_temp, mean, humidity. Second, let's compare! We're using the same data file as for nola_v1, but we're reading it in differently. For each line in the file, create a list containing high_temp, low_temp, mean, humidity, in that order. Compute the Euclidean distance between the current year and the ideal weather. At the end, report back to the user the year with the weather that's closest to their ideal, and the distance. Euclidean Distance Note that your prompt the user for three things (low, high, humidity), but the list you create from their input will have length 4 (high, low, mean, humidity). Make sure the list you create from the file, for each year, is the same length and in the same order. Then you can apply the following: - Given two lists, 11 and 12, of length n, Euclidean distance is defined as: - sqrt((11[0]12[0])2+(11[1]12[1])2+(11[n1]12[n1])2) Note that 2-dimensional lists are not permitted on this homework. You can accomplish everything here with the lists and loops we've covered in class! For full credit under documentation, you must include at least one test case in a block comment at the top of your code. This doesn't have to include the actual closest year and its weather conditions! Something like this, but with your own example. Test case: Ideal: 70, 50, 56 Ideal list becomes: [70,50,60,56] Distance from here to 1937 71,48,59,5,55 (7071)2+(5048)2+(6059.5)2+(5655)2 =1+4+.25+1 And then sqrt (6.25)=2.5 4 Here's an example of what happens when I run my code (as always, yours doesn't need to look exactly the same, but the prompts DO need to be in the same order to make the autograder happy)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions