Questions tagged [python]

Code using the python language.

118 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
956 views

How to call the usd function in the jinja template of quoted.html?

I want to display the cost of the share in Quote tab using the "usd" function defined in helpers.py. I've tried adding app.jinja_env.globals.update(usd=usd)in application.py and then calling the ...
2
votes
1answer
194 views

CS50.io - python 3.6 breaks submit50

I just ran update50 before trying to submit my final project but after doing that and trying to run submit50 the new version of python seems to have broken from what I have seen researching the error ...
1
vote
0answers
58 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, ...
1
vote
1answer
736 views

CS50AI Tic tac toe game with minimax algorithm: I keep receive Invalid move

So my code run, but only the first move, after that I keep getting "Invalid move" message (which was declared by myself) in my result function. I'm not sure what's wrong with my result function, or I ...
1
vote
1answer
468 views

PSET 6 DNA - PROBLEM COUNTING CONSECUTIVE STR SEQUENCES

Im struggling with the PSET6 DNA solution. So far I have opened the dna file and converted it into a dictionary as well as reading the text file. I'm trying to count the consecutive times an STR ...
1
vote
1answer
408 views

API Goodreads issue with the book page

I have been facing an issue with the API, it does not display in the book page in project1 I keep getting the error "Not Found" could someone help me? Check the screenshots of the python code below, ...
1
vote
0answers
170 views

Seding email with python smtplib

For the final project, I'm creating a website that will send a form's of the website to an email address. I'm using flask in python and smtplib in the CS50 IDE. I receive the following error ...
1
vote
1answer
239 views

pset 7 survey: trying to redirect to /sheet returns invalid syntax error

For part of CS50's survey problem from pset7, I'm supposed to redirect from a route that checks if the user has entered in all the survey's fields / appends the values to a csv file --> a route that ...
1
vote
1answer
269 views

issues with buy - functionality works but fails check50

Can't figure this out. My code passes functionality it buys stocks no problem but fails check50 with this error: :( buy handles valid purchase application raised an exception (see log for details) ...
1
vote
0answers
77 views

Python PSET7 /Buy

Can't figure this out. My code passes functionality it buys stocks no problem but fails check50 with this error :( buy handles valid purchase application raised an exception (see log for details) ...
1
vote
0answers
98 views

Pset7 - Quote always returning apology

So, I'm struggling with pset7 a lot (mostly because I've never programmed before either =/) now I'm on quote and it's always rendering an apology after I fill in the form. I can't quite figure out ...
1
vote
0answers
52 views

CS50 Final Project: Unique URL for each user of my flask app (2 of 2)

I have a pending question here: CS50 Final Project: Unique URL for each user of my flask app (posted two days ago) regarding the implementation of unique URLs. This unanswered question was in fact ...
1
vote
1answer
411 views

Pset7: from cs50 import SQL - 'No name SQL in module CS50'

Getting the above error at the head of my pset7 programme in the cs50 ide. Any advice? I've tried updating cs50 a couple times. edit: Also CS50 IDE is displaying an error: 'Error: [object Object]'
1
vote
1answer
1k views

How can I debug in Python?

I am trying to use gdb on a program in python, but it doesn't seem to work the same way it does with programs in c. I tried looking at a few links here: https://sourceware.org/gdb/onlinedocs/gdb/...
0
votes
1answer
25 views

CS50W Project 4 / Network - like counter not always saving to database

I was able to implement a like counter where it keeps track of all the likes. For some reason though, it randomly doesn't save the counter to the database when I submit the PUT request. I can't figure ...
0
votes
0answers
28 views

DNA works with most names except Alice and Albus

I really don't undersrtand why this is happening. I'm trying to finish DNA for pset6. Since more elegant methods were too difficult for me, I decided to compare all values in STR one by one against ...
0
votes
0answers
24 views

Final Project - Get sql to work html, python and flask

On my website for my final project I am able to enter the user info on the website, but the information is not being inserted into the sql table. I feel that I am not understanding something very ...
0
votes
0answers
22 views

CS50W Project 4 / Network - NoReverseMatch

I'm currently on the last project for CS50 Web called Network and am stuck on the Follower spec. I'm trying to get the url in the Following tab to bring you to the profile of the specific user that's ...
0
votes
0answers
16 views

CS50 Web Track - Finance: OSError: [Errno 99] Cannot assign requested address

I'm trying to create a standard 'forgot password' feature for my web application. The issue is, when the user types in their email address and clicks submit to receive a token after which they can ...
0
votes
0answers
6 views

JavaScript functionalities not applied when JavaScript code written in an external .js file for a flask application

I'm working on project2 of CS50's web programming using python and javascript. I've made a .htm file and I need to write some javascript code for the page. I first wrote the code in an external file ...
0
votes
0answers
14 views

Flask-WTF: input field rendered based on the user's selection

I'm trying to make a form where the user logs an action they've done. Because there were too many actions, they are now split into categories and then, based on which category the user chooses, the ...
0
votes
0answers
65 views

PSet 6 DNA: Not able to match variables to dictreader names

I've mostly completed my code for PSet 6, except for the last part where I need to match up the values against the list of names. I know how to get the maximum occurances of the STRs and state the ...
0
votes
0answers
72 views

I'm stack with dna (pset6). can you please help me?

I have divided my code into three main pieces: 1- open the CSV file and read its contents into memory and open the DNA sequence and read its contents into memory 2- compute the longest run of ...
0
votes
1answer
58 views

DNA: Errors in sequences.3 and 18.txt

I have worked hard on writing codes for DNA. Everything works except for sequences/18.txt, which returns "Harry" instead of "No match". The problem still exists in spite of several ...
0
votes
0answers
27 views

DNA.py error: 'TypeError: unsupported operand type(s) for *: 'NoneType' and 'int''. It passes all but 2 of the tests

DNA.py is nearly finished, but it is failing the tests with sequence/15.txt and 16.txt. This is the error message: ~/pset6/dna/ $ python dna.py databases/large.csv sequences/16.txt Traceback (most ...
0
votes
0answers
16 views

pset6 Readability Python: Calculated grades too high

My code below returns incorrect grades. Often it is even two grades higher than it should be. Any ideas where is the mistake? letters = words = sentences = 0 for char in text: if char.isalpha(): ...
0
votes
0answers
52 views

TicTacToe task: PyGame display not rendering

For some reason, the PyGame TicTacToe display is not showing. It just hangs at this: This is the runner.py: import pygame import sys import time import tictactoe as ttt pygame.init() size = width, ...
0
votes
0answers
27 views

i dont know why i got error in the cs50 knight puzzle

from logic import * AKnight = Symbol("A is a Knight") AKnave = Symbol("A is a Knave") BKnight = Symbol("B is a Knight") BKnave = Symbol("B is a Knave") CKnight =...
0
votes
1answer
12 views

Final Project - if statement with regex not working?

Working on my final project and I'm stuck trying to edit user input. The below code should take the first string in a list and check if it's numeric. If it is, great, that's what I want, otherwise, I ...
0
votes
0answers
7 views

I'm wondering how to import Django through my Powershell and how to active Django in my PythonPath

I'm trying to import and active Django in my pythonpath, but I still have this message show up in my manage.py tab on VSCode (I'm using Windows 10 and am finding a lot of Linux inputs): ""&...
0
votes
1answer
17 views

'>' not supported between instances of 'tuple' and 'float'

First I checked for correlation: pear_cor = df.corr(method='pearson') pear_cor Now I have to go through the data and check for the following condition: for val in pear_cor.items(): for x in val: if ...
0
votes
1answer
187 views

Struggling with PSET6 DNA

I've been doing this for quite some time now, but I'm struggling to get the appropriate output. In the below code (which is incomplete as of now, but the main pieces are all on the board), I'm not ...
0
votes
0answers
81 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
117 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
0answers
20 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
28 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
0answers
105 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
83 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
12 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
102 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
48 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
8 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
125 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
2answers
130 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
42 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
7 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
46 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
59 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 ...