Please help me;/ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me;/

import time f=open("City_of_Seattle_Wage_Data_20240329.csv","r")#You guys don't need download this file,just assume this is a list like this: hourly=[55,44.3,67,98,101,120,130,190,120.4] line=f.readlines() hourly=[] for i in range(1,len(line)): #Split the readlines data, use ',' line1 = line[i].split(",") hourly.append(float(line1[-1])) x=[] #This part is hardest part I can't solve ask user a number user=int(input("How many terms u want")) user's number is the liner search number, if the user asks 5, then gets 5 biggest number if user enter n, then get n biggest numbers, then append to the empty list x for user in hourly: if hourly[0]>hourly[user]: x.append[user] print(x)

10th Apr 2024, 3:22 AM
Andybirdgirl
Andybirdgirl - avatar
8 Answers
+ 1
No extra modules allowed
10th Apr 2024, 4:05 AM
Andybirdgirl
Andybirdgirl - avatar
+ 1
Andybirdgirl , Please change your title to something that encapsulates the problem, so it's searchable. Begging is unnecessary and lacks info. It would be easier to run your code if you saved it and shared the link. It's kind of hard to tell what you're trying to do. Without running it, I do see a few things. You never closed the file. To not have to worry about that, learn the with keyword. f.readlines() returns a list of str, which would use 0-based indexing, but you start your range at 1, meaning you skip the first line. Is that because it has a header line with column names you don't need? Also, it's unclear if the file is supposed to contain one line of comma-separated floats or multiple lines of cs floats. I believe hourly will end up only containing the last float from each line, but if you're later trying to find the max, wouldn't you want all the floats of all the lines? etc.
10th Apr 2024, 1:52 PM
Rain
Rain - avatar
+ 1
It seems like you are attempting to implement a program that reads from a CSV file and extracts the highest n values from a list of hourly wages. There are some issues in your code that need to be corrected. Here's an updated version that should achieve what you described attached below. This code snippet: 1. Reads the hourly wage data from the CSV file. 2. Extracts the hourly wage values from the lines read from the file. 3. Asks the user for a number or 'n' to get all the highest hourly wages. 4. Finds the highest n hourly wages in the list. 5. Prints the list of top hourly wages. Make sure to replace the placeholder CSV file name with your actual CSV file name. https://sololearn.com/compiler-playground/cY6690p7lM0s/?ref=app
10th Apr 2024, 8:17 PM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar
+ 1
Andybirdgirl This code snippet I attached below reads the hourly wages from the CSV file, sorts them using the selection sort algorithm, and then prints the n highest hourly wages based on user input. Coding is fun, enjoy ma'am! https://sololearn.com/compiler-playground/crN9wBGnGaF8/?ref=app
12th Apr 2024, 5:41 AM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar
+ 1
Thank u
13th Apr 2024, 3:20 AM
Andybirdgirl
Andybirdgirl - avatar
+ 1
U saved me
13th Apr 2024, 3:25 AM
Andybirdgirl
Andybirdgirl - avatar
0
How to do this with select sort?
12th Apr 2024, 4:07 AM
Andybirdgirl
Andybirdgirl - avatar
0
Andybirdgirl You're welcome 🤗
15th Apr 2024, 3:49 AM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar