Questions tagged [python]

Code using the python language.

Filter by
Sorted by
Tagged with
0
votes
1answer
9 views

Keyerror Won't Go Away

I keep getting a key-error in pset7, Houses: Traceback (most recent call last): File "import.py", line 24, in <module> names = cutting(row["name"]) KeyError: 'name' ...
0
votes
1answer
13 views

Finance index.html is not rendering values from my index function

I'm having some issues trying to render values on my index.html page. In my index function, I created a dictionary of values from my transactions table to grab each record of my share symbols, share ...
0
votes
0answers
27 views

how do I perform a search

This is project one for wiki and I am stuck this is my last thing to do. below are screenshots of the views.py, util.py and template. We are suppose to use the functions from util.py(This is the last ...
0
votes
1answer
9 views

Why updating a dictionary is not working?

for row in rowsList: if row['middle'] is None: row['middle'] == "" print("{} {} {}, born {}".format(row['first'], row['middle'], row['last'], row['birth'])) Where ...
0
votes
1answer
30 views

Pset6 DNA Not matching to names in the database

The print statements seem to turn out what I hoped for up until trying to compare the STR counts to the database STR counts. I would just appreciate any pointers of where I'm going wrong thanks. ...
0
votes
1answer
17 views

Python - for loop not being executed, leading to NameError of variables defined in the loop

It's a simple Python program to find the number of primes until a certain number. The for z in range(1,y): loop does not execute, but rather execution jumps to the print(count," Pr...) statement ...
0
votes
0answers
13 views

I keep getting invalid syntax at else. I am trying to redirect a page

here is the code. I keep getting invalid syntax at else. Can someone explain why and help please.
0
votes
0answers
20 views

I keep getting - TypeError: unhashable typ

can't get page to redirect please help. I keep getting the error TypeError: unhashable type: 'dict' at line: return HttpResponseRedirect (reverse("encyclopedia:index", { "entries":...
0
votes
3answers
39 views

PSET6 Mario Python

I have been experiementing with this code for a couple hours and have come across an issue with each implementation. I can no longer put in any time at the moment so I figured I would go ahead and ask....
0
votes
1answer
39 views

CS50 Houses : Output is correct in my console but error in check50

I am working on the CS50 course by Harvard EDx. The output for CS50 - Houses is correct in my console. However, check50 which is validates and evaluates the response gives an error. I have checked the ...
0
votes
0answers
62 views

PSET6 DNA [SPOILER] Refactor

I have solved the problem however is there anyway to optimize this further? Also, how do I judge the time-space complexity of the same? import csv from sys import argv, exit from csv import reader, ...
0
votes
0answers
17 views

I have been trying to fetch book reviews from Goodreeads API

I got this sqlalchemy.exc.ProgrammingError sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'RowProxy' while trying to fetch book reviews from Goodreads API with the ...
0
votes
0answers
53 views

Confused about DNA in pset6

I've just started DNA, and I've got what seems to be a working algorithm to see if the count of the STRs in the database and sequence are the same, but it does not seem to be working. I've been a bit ...
0
votes
0answers
23 views

i dont know why i'm getting 45% when it looks like it's working

while True: n=int (input("enter height: ")) if n>=1 and n<=8: break k = 2 * n - 2 for i in range(0, n): for j in range(0, k): print(end=" ") k = k - 2 for j in ...
0
votes
0answers
10 views

Ive been getting a syntax error for this Python code. Id appreciate If someone could help me

This is from a python course by mosh The code is this -> import pandas as pd from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn....
0
votes
0answers
74 views

cs50 pset6 DNA, minor differences in counting STRs |Spoiler entire code included|

My code counts STRs for some people correctly, but for others the difference is very small. For example for python dna.py databases/large.csv sequences/5.txt expected output is Luna, whose STR counts ...
0
votes
0answers
28 views

PSET 6 - credit, pythonic or not?

I didn't do credit for problem set 1 (I chose less comfortable) so I don't know what the C implementation was. I was wondering if you guys think this is too C-like or if it's okay for python code. Any ...
0
votes
0answers
6 views

CS50w flack (chat) project: channel user list stops updating after a while, can't understand why

This is a weird one, so I've recorded a short video to better illustrate the problem. As an additional feature to my chat app I have a panel on the right that displays the users currently on the ...
0
votes
1answer
91 views

PS6 - DNA (Python) Weird problem counting STRs

Which part of the problem are you working on? I am at a very early stage of the problem, trying to scan a specific sequence for STRs, counting how many times they show up and storing this count as a ...
0
votes
1answer
38 views

Finance: UNIQUE constraint failed: users.username

I've been struggling with this for days. Ignore the '1234' hardcoded into the "insert into" line, just using that to isolate problems. The problem I'm facing is with the username being ...
0
votes
1answer
25 views

Finance - Missing Value For Placeholder

As far as I can tell, I have the value set - username = username. Am I missing something stupid here? Code: @app.route("/register", methods=["GET", "POST"]) def ...
0
votes
0answers
6 views

Does __tablename__ create a new table for each object? And what is .query.all? Is it a method?

I am really confused In CS50'S Web Programming with Python and Javascript-ORMs and APIs. There is weird syntax like class.query.all. What is Its definition (a method, a function, etc).
0
votes
0answers
24 views

CS50 PSET6 Credit

I am working on the PSET6 CREDIT of cs50 in Pyhton. I can make my program work properly. When I input 378282246310005 as a credit card number, the output should be AMEX. However, no matter the input, ...
0
votes
0answers
23 views

Error in Python--Cs50 week 6

I'm just starting cs50's week 6 in python. I copied a small program written by David in the lecture to run in my cs50 IDE, but I'm getting a strange error. I believe the error is about the get_string ...
0
votes
1answer
126 views

PSET6: DNA returns “no match”

import csv import sys def maxrepeats(sequences, substring): # calculate maximum consecutive frequency for each STR repeats = [0] * (len(sequences)+1) for i in range(len(sequences)-len(...
0
votes
1answer
18 views

RuntimeError: missing value for placeholder (:name)

all! I'm doing the final project, and I have a form whose contents I'm trying to submit to a database. My python code is: @app.route("/Contact.html", methods=["GET", "POST"]) def Contact(): if ...
0
votes
1answer
63 views

pset6 DNA - range() not working as expected

DNA was a breeze until I got to the part where I have to check the dna sequences for patterns. Regardless of wich file I pass to the program it always detects only 1 repetition for every pattern. ...
0
votes
1answer
49 views

What are the requirements for Week 6 Mario (more)? My code works but the grade book shows only 96% completeness

I tried two different variations but both reach 96% completeness code 1: from cs50 import get_int while True: height = get_int("Height: ") if height < 9 and height > 0: break ...
0
votes
0answers
55 views

pset7/houses: db.execute(“INSERT”) fails to export data to students.db

I am using pandas to read in the csv file, since I'm familiar with dataframes from R. But I think that may not be the issue here, which is that db.execute fails to export data to students.db. The code,...
0
votes
0answers
65 views

PSET6 - DNA - Code works for small database, but not large

I believe that the issue comes from my 'sequencing' function. When I run the small database, everything works, however, when I run the large database, the counts of specific STRs are incorrect. I'm ...
0
votes
1answer
66 views

Problem with path reversing in CS50 AI -> Degrees

I have a problem in my code that reverses the path my BFS search algorythm takes. The first project in the CS50 Introduction to artificial intelligence is called degrees and finds a path from one ...
0
votes
0answers
16 views

Couldn't run the code

I'm trying to run the below code in cmd but I couldn't, it is saying " Traceback (most recent call last): File "list.py", line 3, in from sqlalchemy import create_engine ModuleNotFoundError: No ...
1
vote
0answers
33 views

PSET6: dna.py, updating dictionary

I'm struggling with Python, specifically adding/updating keys and values in a dictionary. This is my code so far (I know it's probably far from perfect, this is my first time working with Python, ...
0
votes
1answer
151 views

Pset 6 Readability returns higher than expected grade

My code is right below I am unable to find the issue because my C code for readability was basically the same(except syntax and formatting of course!) and it was working perfectly. This Python code is ...
0
votes
1answer
86 views

Pset6, DNA - Convert all columns in a list to integers, skipping the first column

I'm trying to figure out how to take the csv file I opened and convert specific columns to ints since when the csv is opened and read, every element becomes an int. Inside of the for row in csv_list:...
0
votes
1answer
37 views

Counter fails to update for DNA

My dna program always returns no match and after debugging it I've pin pointed the problem to the counter not updating correctly. My program finds the correct number of matches, which I've confirmed ...
0
votes
1answer
52 views

Can't import books.csv using import.py

I'm on a project1, here is the link to it: https://docs.cs50.net/ocw/web/projects/1/project1.html I've successfully made a Table books using my Python script, however when I try to import the "books....
0
votes
1answer
20 views

Absolute path in Cloud9

I am trying to upload an image to the SQLite database in a blob format. I run in to the problem when I am trying to get an absolute path to the image. The error I am getting is FileNotFoundError: [...
0
votes
0answers
12 views

Why I get a MultiValueDictKeyError when getting data from POST request?

I'm currently learning in Django, and in this fetch request, I always get the same error: topup.html let data = new FormData(); data.append('amount', document.getElementById(...
0
votes
0answers
43 views

CS50AI Project Knights Puzzle 1

Can anyone help to explain the logic behind puzzle 1 thanks!! Please correct me if I'm wrong but this is what I wrote and I somehow stumbled to the answer. Without keying in the information that ...
0
votes
0answers
87 views

solved pset6 BUT still wondering

while reading the CSV file in these lines : csv_file = open(sys.argv[1], "r") # reading the csv file into memoery csv_reader = csv.DictReader(csv_file) when i tried to make a copy of the csv_reader ...
0
votes
0answers
44 views

cs50ai tic tac toe minimax TypeError: '>' not supported between instances of 'NoneType' and 'float'

I'm working on the tic tac toe problem set. The whole game is working correctly, however I'm having some troubles kicking off the AI. I've been running the game with the computer doing random moves, ...
0
votes
0answers
18 views

Problem with Flask Flashing message - messages appears twice

I'm newbie at Flask. I am trying to manage the flash alerts to appear where I want them. When I write the code get_flashed_messages() in the .html module the messages appears twice, without this code ...
0
votes
0answers
72 views

Getting a NameError in the PageRank problem in CS50's Introduction to AI with Python

Here's the implementation code :- https://gist.github.com/ShaunakInamdar/9a914b43bb778aac04e8f254f3e5329f I'm getting an error in line 89 saying "NameError: name 'pageRank' not defined." Somebody ...
0
votes
1answer
29 views

Internal Error Served if user doesn't own any shares or sell all his shares in Finance

When i sell all the shares i own or even in the case of a new registered user who doesn't own any shares; it doesn't redirect to "/" i.e the main index page but serves me an internal error. It works ...
0
votes
1answer
54 views

Problem in importing from csv file

I am currently trying to import the contents of the books.csv file into my PostgreSQL database on Adminer. Here's my code: import csv import os from sqlalchemy import create_engine from sqlalchemy....
0
votes
0answers
88 views

NameError: name 'db' is not defined

I've made a simple code using python, where with the help of Flask_sqlalchemy I am trying to create 2 tables in a database which is being hosted by Heroku. The file db.py contains my table details ...
0
votes
1answer
70 views

pset6 mario/more - output is seemingly correct, however failing tests

I've just finished mario/more in pset6, however, it does not pass the tests. The actual and expected outputs are identical, so is the expected string. The pyramid also looks identical to the c ...
0
votes
0answers
106 views

Problems with PSET6 – DNA

I don't understand why my code below isn't working. Instead of printing out the name of the person, it simply prints out No match found every time, even when there is supposed to be a match. If anyone ...
0
votes
1answer
49 views

Pset7 Houses, what does my error message mean?

Whenever I run my code, I get a strange error message because of my code. It is because of my SQL code, but I followed all of the instructions, and even tried some other SQL code, which worked ...

1
2 3 4 5 6