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.

Filter by
Sorted by
Tagged with
9
votes
3answers
599 views

School House Points (Python + SQLite)

I am creating a database to store house points for our school running events. I would like to be able to tally all the points for the houses and it is working fine, however, I think it may be a bit ...
2
votes
1answer
30 views

Find articulation points/ cut vertices in graph

I would like to get some feedback on my completed code that finds and displays the articulation vertices in an undirected graph. I included a test case within the code, it should (and does) print <...
6
votes
3answers
301 views

Bishop game - python

A bishop can capture any other bishop if it lies along the same diagonal line, so long as no other bishop is in its path. Given a list of coordinates of the bishops locations, and a board size, ...
3
votes
2answers
95 views

Calculate mean and standard error of a generator in Python

The goal of the following code is to calculate the mean and the standard error of vectors of randomly-generated numbers. I am looking for feedback both on the correctness of the calculation, and on ...
0
votes
2answers
63 views

A regex pattern that matches all forms of integers and decimal numbers in Python

The question is pretty self-explanatory. I wrote a regex pattern which should (in theory) match all possible integers and decimal numbers. The pattern is as follows: ...
0
votes
1answer
57 views

Port the data from a TEXT file to Postgres table using Python

I have written the below code to read a huge text file of size 20+ MB and insert the values to a PostgreSQL table. The code is working fine, but I'm facing below issues in the code. 1) The code is ...
5
votes
1answer
69 views

Text-based fighting game in Python 3.0

I have began to practice Python after a couple of years and for my first Project, i decided to make a fighting/rpg-like game with different characters. So far, I am only familiar with loops and ...
2
votes
1answer
62 views

Python Script to download images and videos from a user's profile on Instagram

The script downloads images and videos from a user's profile page on Instagram. It works fine, but I'd like to know if there are ways to improve it. All ideas and suggestions are welcome. ...
1
vote
1answer
25 views

Command Design Pattern Implementation: Moving Robot with Undo-movement (Python)

I'm learning about the command design pattern and would like you to critique it for division of responsibility, especially with regards to how the robot "undoes" commands it previously executed and ...
2
votes
1answer
38 views

test oriented design; Python test script to test a company's API, print test results, log exceptions

I'd like some constructive feedback on the code that I have written to test the API for smartsh33t.com I wrote it in Python. I wrote the program to take .json files and read them into the testrunner....
1
vote
0answers
28 views

Parsing and plotting with numpy (or pandas)

I am trying to improve the following code to make it more broadly applicable and quick to use. ...
3
votes
1answer
50 views

the fox is black - a simple image scraper

I wrote a simple image scraper for the Desktop Wallpaper project by The Fox is Black. The site is a fantastic (yet, apparently dead) blog full of fabulous images. However, there's no way to download ...
4
votes
0answers
45 views

Scraping a hiring website using python's requests and BeautifulSoup

I'm designing a scraping application using python, requests and BeautifulSoup4. I decided to divide the logic into two classes: Spider : gets the base url ...
4
votes
2answers
48 views

String validation based on multiple criteria

I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ... In the first line, print ...
5
votes
1answer
44 views

SQL Bulk status update

Context I'm a duck retailer. I rent ducks to farmers, and when they don't need them anymore, I get them back. In order to track which ducks I rented to whom, I have a PostGreSQL database that I keep ...
8
votes
1answer
97 views

Geektrust: Solve War problem in a OO way in Python

I solved this programming challenge whose objective is to come up with an OO solution to the problem. The problem statement is quite verbose and the tl;dr version would be: Given an enemy army(...
4
votes
1answer
100 views

Python Calculator using Postfix Expressions

Improved upon my previous calculator program. This program has the following features: Gives information using session prompts. Supports all common operators. Follows operator precedence. Use of ...
2
votes
2answers
172 views

PDF page & word count, recursive searching of directory tree, output to excel

I wrote this program as part of a work-related problem but with a focus on improving my Python skills. The program was needed to do a word count PDF files. The problem was there were a large number of ...
4
votes
2answers
80 views

Regex Version of strip()

This problem is from Automate The Boring Stuff using Python - Chapter 7. Write a function that takes a string and does the same thing as the strip() string method. If no other arguments are ...
1
vote
1answer
77 views

Maximum Width binary tree

Here is my code for the LeetCode problem For a given binary tree, find the maximum width of the binary tree. The width of one level is defined as the length between the end-nodes even if there are <...
2
votes
1answer
82 views

Monty Hall problem in Python3

Some years ago I made a Monty Hall simulations in Java, and now I decided to give it a go in Python, after learning (yet another) the language at university. I decided to make a generalized, object-...
3
votes
1answer
126 views

Simple sharding of delimited files to more sophisticated

A while back I came across the issue of having a large delimited file where I wanted to simply parallelize my python code across each line of the file. However, doing so all at once either took up too ...
5
votes
1answer
102 views

Python script to rename images based on descriptions in a text file

I like to collect images for my desktop background, but the problem is sometimes the image names don't represent what the image is. I decided to write a script that reads a text file that contains the ...
3
votes
2answers
124 views

Jump Game - Leetcode

Below is my solution for the LeetCode Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents ...
1
vote
1answer
169 views

Python: Heapsort

I am beginner in python and I am learing about syntax and other functions in python by writing Algorithm and Data Structure programs. How can this code be improved? ...
3
votes
1answer
97 views

Simple python scheduled tasks script that runs once daily

I want to execute a python script daily and thereby want to schedules task as follows. The idea is that the script will run once daily, and the script will then decide what tasks to be done today. ...
4
votes
4answers
1k views

Strong Password Detection in Python

This is a problem from "Automate the boring stuff". Write a function that uses regular expressions to make sure the password string it is passed is strong. A strong password is defined as one ...
5
votes
2answers
67 views

E-commerce scraper needs shortening

How would I go about shortening this code? I'm sure there's a smarter way to write the code. It's working fine, it's just ugly. It is a way to scrape the number of items on an e-commerce site. <...
7
votes
1answer
66 views

Generating Latin hypercube samples with numpy

I wrote some code to generate Latin hypercube samples for interpolation over high-dimensional parameter spaces. Latin hypercubes are essentially collections of points on a hypercube that are placed on ...
2
votes
1answer
137 views

Project Euler #3 with Python

I tried to solve some Euler's problems, this is the solution I found for problem #3 with Python. The problem asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor ...
5
votes
1answer
148 views

Find website URLs that begin with http:// or https://

This is a problem from Automate the Boring Stuff from "Pattern Matching with Regular Expression". I am a beginner in Python and the purpose of this program is to match urls which start with ...
7
votes
2answers
73 views

Python class compressor

After watching this presentation, I decided that it would be a good project for me to undergo to practice my python skills. A summary of the presentation: Jack ...
9
votes
3answers
892 views

KenKen solver - Python

Here is my code for the KenKen puzzle: The user must fill in each embolded regions with numbers in the range 1-n where n is the board dimensions (e.g: 4*4, n=4) ...
3
votes
3answers
149 views

Compute binary sum with Python 3

I tried to make a function able to compute the binary sum. Binary numbers are passed as list composed of 1 and 0, like ...
1
vote
1answer
42 views

Cube root in Python 3 using Bisection Search: Numbers in -1 to 0 [closed]

Here is my code, which doesn't seem to work for numbers in between -1 and 0 (works perfectly fine otherwise) I think the code enters an infinite loop, somehow, hence I get no result after entering ...
0
votes
1answer
120 views

Using another function on modified dictionary

This is based upon an exercise in chapter 5 of Automate the Boring Stuff with Python. This code contains functions addToInventory which modifies a given inventory ...
0
votes
2answers
94 views

Descriptive quantity (one, two, many) from number [closed]

I just write a simple method which returns a string based on the number in accepts as a parameter. I used if/elif/esle here but I think for this simple scenario I ...
8
votes
3answers
2k views

Tiny URL creator

Coding challenge: Convert a given long URL into a Tiny URL. The length of this Tiny URL should be fixed and the same for all URLs. You should return the full URL if given a shortened URL. I am ...
1
vote
2answers
158 views

My Sal's Shipping challenge on Codecademy

This is my attempt on the Python 3 Sal's Shipping challenge on Codecademy (Challenge Link (instructions in the link)). I'd really appreciate anyone to take the time to review my code. I'm a very new ...
7
votes
6answers
1k views

Find max number you can create from an array of numbers

Was asked this in an interview yesterday: You are given an array of numbers (not digits, but numbers: e.g. 9, 23, 184, 102, etc.) - you need to construct the largest number from it. For example: you ...
3
votes
1answer
65 views

Find minimal number of days to meet all your friends

I was asked this in an interview yesterday: You get an array of segments (segment contains 2 numbers, representing days count (say in a month, but could be in a year, etc.): start, end). You need to ...
-2
votes
1answer
31 views

A game that deals a high card to one of two players [closed]

So for my class, I have to design a game that will deal out one card to for each player. I also need to use functions to accomplish this one for the high card game, and another for the face value of ...
1
vote
1answer
73 views

String Rotation

I have solved a previous year question of 2018 codevita (link) in Python. Problem Description: Rotate a given String in the specified direction by specified magnitude. After each rotation make a ...
3
votes
0answers
33 views

How can I make my Pygame Tic Tac Toe game better?

I have this code ready and it works just fine. But what are the ways by which I can improve this code? I have no CS background and this is my first coding project. I could not paste my entire code so ...
1
vote
1answer
38 views

Manual Regression Tree using Python

I wrote a code to create a regression tree for a synthetic train data of size Np. The idea is, first I have the source node (which consists of all set of points) ...
1
vote
0answers
52 views

Python: Quick Sort

How to improve this code? In C++ we use templates to write function for all data types. How to write such code in python? ...
5
votes
1answer
124 views

pythonic way to split bytes

I have incoming data from an absolute rotary encoder. It is 24 bits wide. 12 bits are the number of turns and 12 bits are the angle. I'm reading the data with an Arduino and sending it to the ...
4
votes
1answer
34 views

For each element in a list, finding the element in a second list, that minimizes a distance function

Getting started: For a given number x (say -5) I want to know which element of a list y (...
6
votes
2answers
174 views

pydoro - terminal tomato timer

I've recently created a tomato timer for terminal. It's hosted in github. My concerns are how Pythonic my code is? Is the way I'm handling state transitions good? Which areas of the text user ...
1
vote
1answer
52 views

Python: Merge sort

How can I improve this code? ...