Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

0
votes
0answers
20 views

Pygame Flappy Bird Clone Black Screen

I am new to coding python, and I followed everything in a 4hr video tutorial but however, I get a black screen when I run my game. I am trying to finish this game for my long-term-project in high-...
-4
votes
0answers
20 views

Not able to print correct confusion matrix and also in heatmap values are printing in example 2e+2, e+4 etc etc [on hold]

import numpy as np import matplotlib.pyplot as plt import seaborn as sns import pandas as pd from keras.models import Sequential from keras.layers import Convolution2D from ...
2
votes
2answers
51 views

Simple Web Crawler for Small Sites

This script is my web crawlerfor small sites. Can you possibly review it for best coding practices? Code ...
2
votes
2answers
40 views

Python - Random Mandala

I did a project in Python where I combined user-input, random, and the turtle module to make a sort of "Mandala Generator", or a program that can generate a simple design either randomly or by the ...
-1
votes
0answers
18 views

When to couple output from one class as the input to another class? [on hold]

I am trying to better plan the class structures of a large code base in python. The project is a data science project involving data cleaning, data analysis, etc. I model all the data cleaning tasks ...
-1
votes
0answers
44 views

Correct Python script structure [on hold]

I've been programming in Python for some time now and I've always used the below structure to organize my code. Lately, I've been wondering if this structure is an ideal and correct one to use ...
0
votes
1answer
27 views

Python code for handling HTTP cookies

We would like for a code review for our Python code. The code is written in Python 3.7 and is part of a class handling HTTP cookies. The code: ...
-1
votes
0answers
30 views

Multiprocessing a for loop in Time series [on hold]

I want to use multiprocessing for a 'For loop'. So basically from a another dataframe I am passing ID,PID to main dataframe, so depends on ID,PID it will filter the dataframe & build a model. I ...
7
votes
2answers
75 views

Maze generator for teaching Python 3

I am teaching programming (in this case - 1 on 1 tutoring of a teenager interested in programming) and this code will be a final stage of a progression toward program generating a maze. Any comments ...
6
votes
3answers
2k views

Extract all GPU name, model and GPU ram

I currently use this code to extract the required GPU data. Can you review this method for efficiency or best coding practices? Code ...
1
vote
1answer
73 views

2-Player Tank Battle Game

I've created a 2-player tank battle game. The code however seems like it could be greatly simplified and there are a few issues. One of which is the hitboxes of the tank seem a bit unreliable. ...
3
votes
1answer
34 views

Getting limited user input: strings and numbers

I posted part of this module earlier (here). I implemented that feedback and now am looking for another round of gut checking. Questions/Concerns I have: Does the way I've structured my functions ...
1
vote
0answers
36 views

Python - Speed up nested for loops in numerical experiments

I am trying to run some numerical experiments, and wondered if there was any way to run my code faster. The function runs over combinations of several parameters so in my mind I thought the best thing ...
4
votes
0answers
42 views

Basic Python HTTP Server

It's an extremely simply HTTP server in Python using the socket library, and a few others to get the MIME type, etc... I've also avoided the ../../ vulnerability, ...
25
votes
5answers
3k views

Fishing simulator

I'm new to Python, for a school project I created a "fishing simulator". Basically, it is a use of random. I know that my code is repetitive towards the end, but I don't know how to simplify it. <...
2
votes
1answer
51 views

Analyzing patient treatment data using Pandas

I work in the population health industry and get contracts from commercial companies to conduct research on their products. This is the general code to identify target patient groups from a provincial ...
1
vote
1answer
60 views

Remove nested for loops in python [on hold]

I have the following working code, but it is too slow because I have to run the same code for several files inside a folder. Please help me avoid the nested for loop or make it more efficient. ...
3
votes
1answer
69 views

First Python program: Tic-Tac-Toe (Followup)

I am unsure if I followed the the suggestions on my previous post. I have only been working on programming for about 3 weeks so any more suggestions or insight would be more than welcomed. ...
4
votes
0answers
28 views

Decorate a python function to work as a Google Cloud Function

I wrote this for a class project, the backend for this dog voting website. I noticed duplicate code among multiple functions I was writing to be deployed as a cloud function: they all were wrapped in ...
3
votes
1answer
55 views

Google Kick Start Practice Round 2019 - Mural

My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated. Problem Thanh wants to paint a wonderful mural on a wall that is N ...
4
votes
0answers
30 views

Convert Amazon transaction data for import into accounting system

At the end of each billing cycle, Amazon generates a raw transaction file for my store's orders that cycle. I am converting that raw transaction file into a .csv file to be imported into my accounting ...
3
votes
2answers
103 views
+50

Implement BinarySearchTree class in python

I am currently study the basic data structure and trying to implement everything as I go. can anyone give me some feedback about class BinarySearchTree how to make the code more elegant. any review ...
12
votes
4answers
5k views

Pokemon Turn Based battle (Python)

This is based off the popular Pokemon Turn Based project (here). GOAL Write a simple game that allows the user and the computer to take turns selecting moves to use against each other. Both ...
3
votes
0answers
25 views

Feedback on Object-Oriented ETL Class Structure for Computing Profit Summary Data

I am using Python 3 and pandas 0.24.2 to do some data processing and ETL flows. I have followed this pattern a couple of times and it is really bothering me but I am not sure which direction to go to ...
8
votes
2answers
65 views

First Python GUI Calculator with exponentiation function and percents

I made my first Python project with the help of Tkinter. I was trying to make it works like iPhone calculator. I am a beginner and I am looking for ways to improve my code. I use PyCharm and got rid ...
6
votes
1answer
37 views

List subclasses of a class

Description Given a class, return all its subclasses (recursively). As you can see I've eliminated recursion using a stack. What I want reviewed Is there a better way to do this? How can I make ...
2
votes
1answer
31 views

Wipe sensitive information from memory in Python

I have come up with the following method to remove sensitive information with the help of the garbage collector: ...
2
votes
0answers
15 views

spark takes long time for checking an array of items present in another array

I am new to spark. I have two dataframes df1 and df2. df1 has three rows. df2 has more than few million rows. I want to check whether all items in df2 are in transaction of df1, if so sum up the costs....
1
vote
1answer
42 views

tuple initialization in a loop

I would like to do the following: I have a list data of 3-tuples that I need to go through, for each tuple base_tuple I want to ...
2
votes
1answer
26 views

AES CTR mode encryption with HMAC

I am trying to implement AES CTR encryption mode with HMAC authentication for messages. It's encrypting and decrypting fine as long as the key length is 64 bytes, since AES key and HMAC key are ...
1
vote
2answers
41 views

Leetcode Next Permutation in Python

My solution to Leetcode Next Permutation in Python. Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is ...
1
vote
1answer
51 views

Tic-Tac-Toe game in Python 3

I have written a code for a tic-tac-toe game and it works well. But, I don't know whether it is an efficient one. Any help on how to optimize it? ...
4
votes
1answer
39 views

Eliminate unnecessary looping while parsing cable modem status table

I am writing a Python script that will be used to generate line protocol for inserting metrics into an InfluxDB. I'm parsing the status page of my cable modem. That part works. I receive the data and ...
1
vote
1answer
41 views

Programming Challenge from Kattis: Distinctive Characters

I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. ...
0
votes
0answers
40 views

Exploring code objects

EDIT start The first version of my solution was wrong (the usage of compile() function), for details see StackOverflow. The solution has been fixed and now it ...
3
votes
1answer
35 views

Logging with decorators (passing log file name as argument)

This is for some quantum mechanics software so there will be references to molecules/atoms etc but the core issue is a python logging one, unrelated to all that. I have a couple of logging decorators,...
6
votes
2answers
74 views

Quantum random number generator

I'm working on a Quantum Random Number Generator and wanted to get some feedback on the project so far. I'm using PyQuil to generate machine code for the quantum computer, first to create a bell ...
1
vote
0answers
26 views

Python Hangman (guess the word) game

I implemented a Hangman/guess the word clone in Python. This is my first attempt at making an actual interactive app instead of just a list of functions or a static program. It is also the first time ...
4
votes
0answers
33 views

Iteratively Build a Summary Dataset in an Effective Way

This is a problem I find a lot!! Can I achieve this goal without consuming so much time? My code below achieves what I want it to achieve. However, I believe it could be a lot more efficient and ...
9
votes
2answers
569 views

Read/write a pipe-delimited file line by line with some simple text manipulation

This code that I wrote is supposed to read/write a pipe-delimited file line by line to a new file with some simple text manipulation. (It also adds two new columns) and publishes a "Status Update" ...
4
votes
2answers
75 views

Take a list of nums and return max and min

Exercise 6: Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the numbers at the end when the user enters “done”. Write the program to store the ...
5
votes
2answers
109 views

Programming Challenge from Kattis: Watchdog

I've tried to solve the kattis-challenge called Watchdog. My code works just fine, but it was too slow on the last test. I'm wondering if anyone sees any big algorithmic performance issues. A short ...
5
votes
1answer
35 views

Locating an image file in a pyGame [closed]

I am writing a simple game with pyGame. Structure-wise, I have separated my game into several files: main.py # the main runner, it loads up the environment ...
12
votes
5answers
6k views

Yu-Gi-Oh cards in Python 3

I made a project in Python 3.7.1 that includes classes to create Yu-Gi-Oh cards. This isn't the entire game; it is just the cards itself. I will create the entire game later. I want feedback on how to ...
5
votes
2answers
624 views

Calculator final project in Python

In my final project for my Python course, I am required to create a calculator program. I really need someone to look over my code and tell me if I have met all the requirements for this project. ...
8
votes
3answers
231 views

Method for adding error messages to a dictionary given a key

I want this method to be completely understandable just from looking at the code and comments only. ...
7
votes
2answers
59 views

Method for formatting a decimal number in Python using the given maximum number of digits and decimal places

The question itself should be fairly self-explanatory. My method takes in value, max_digits, and ...
6
votes
3answers
406 views

Elegant way to replace substring in a regex with optional groups in Python?

Given a string taken from the following set: strings = [ "The sky is blue and I like it", "The tree is green and I love it", "A lemon is yellow" ] I ...
8
votes
2answers
899 views

Text adventure game code

I'm just looking for someone to review this and see if it all works, here you go. I must mention that once you start this code adventure, all answers to questions must be in single quotes (i.e. ...