The CS50 AI Duck is trained to work like a tutor. When you ask for help, it will ask you questions to see what you understand first. If you make an effort to answer the question and give it more information, it can see what you're missing and give you more helpful guidance.
Quack. I am CS50's duck debugger (ddb), an experimental AI for rubberducking. Quack quack. My replies might not always be accurate, so always think critically and let me know if you think that I've erred. Conversations are logged. Quack quack quack.
Quack. I am CS50's duck debugger (ddb), an experimental AI for rubberducking. Quack quack. My replies might not always be accurate, so always think critically and let me know if you think that I've erred. Conversations are logged. Quack quack quack.
my code isn't working to find the largest row
data_rows = get_collision_data()
largeval = None
for row in data_rows:
column = 'Collisions per billion miles'
if largeval == None or row[column] > largeval[column]:
largval = row
print(largval)
my code isn't working to find the largest row
data_rows = get_collision_data()
largeval = None
for row in data_rows:
column = 'Collisions per billion miles'
if largeval == None or row[column] > largeval[column]:
largval = row
print(largval)
It looks like you're trying to find the row with the largest value in a specific column. Can you tell me more about what's not working? Are you getting an error message, or is the output not what you expect?
It looks like you're trying to find the row with the largest value in a specific column. Can you tell me more about what's not working? Are you getting an error message, or is the output not what you expect?
no errors
No error message. The output is always just the last row in my data
Great, no errors is a good start! Let's look at the logic together. You mentioned that your code isn't working to find the largest row. What is the output you're getting, and how does it differ from what you expect?
It sounds like the issue might be with the condition in your if statement. Can you walk me through your logic there?
it prints the wrong row
I check if largeval is none to set it on the first pass of the loop. Then I check if largeval is smaller than the row to update it if I find a row with a larger value
Let's look at the logic in your code. You're comparing the current row's value to the largest value found so far. Do you see any potential issues with this comparison?
Your logic seems sound! Let's take a closer look at the code. I noticed a small typo in your code. Can you spot it?
no, help me
I tried but no
No problem! Let's go through the comparison step by step. In your code, you're comparing the current row's value to the largest value found so far. How are you storing the largest value found so far?
No worries! Let's look at the code together. In your if statement, you compare largeval to the current row. But in the line where you update largeval, you accidentally wrote largval instead. Do you think this could be causing the issue?
in largeval
largval instead of largeval.
Great! You're storing the largest value found so far in largeval. Now, let's look at the comparison. How are you comparing the current row's value to largeval?