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
11
votes
3answers
715 views

Installing “mods” with Python

A little disclaimer: you're going to have a field day with this. It's horrible. Looking at it makes me want to vomit, and don't ask me to explain it, because I've long forgotten what I was thinking ...
4
votes
1answer
231 views

Cutting strings into smaller ones based on specific criteria

I've got this largish (for me) script, and I want to see if anybody could tell me if there are any ways to improve it, both in terms of speed, amount of code and the quality of the code. I still ...
6
votes
1answer
1k views

Hooking with Python3 Decorators

I wrote this prototype after reading the Wikipedia article on hooking. I didn't bother to read any of the code examples listed there because, well, I just didn't. I don't have a good excuse. The ...
7
votes
1answer
158 views

More efficient way of removing line indices?

After profiling my current script I've found that nearly 100% of the run time (and I'm not surprised) comes from the following function: ...
3
votes
1answer
163 views

Twirling cursor

I'm writing a twirling cursor, which is a cursor that twirls in place in the console. In Forth, this takes just 3 lines, whereas in Python3 I have this: ...
7
votes
3answers
3k views

Simple MPG calculator in Python

I am a self taught coder taking a Programming Fundamentals class to work towards a degree. It's based on Python, which I'm not as familiar with as other languages. I added error handling like I would ...
10
votes
2answers
10k views

Optimizing solution for Project Euler Problem #23 (non-abundant sums)

Project Euler Problem 23 asks: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 ...
5
votes
1answer
3k views

XLSX writer implementation

We have multiple scripts which write into XLSX with the same format, into a different format or slide variation. I am trying to write an API which saves time for other programs, but I need input on ...
7
votes
4answers
156 views

Record Cataloging Program

I made a simple program to catalog some old records I have. It seems a tad redundant in the searching function. Does anyone know what I can do about that? ...
2
votes
1answer
512 views

Python Hangman feedback

Just looking for some feedback on a hangman script. It works perfectly fine; I'm just trying to master the Python language, and the best place way to get better is to ask the true masters! ...
3
votes
1answer
349 views

Python data massager

Below is a pretty simple Python script to ingest some data, massage it as necessary, append a column, sort it, and then write it back to another file. Still learning all the Python best practices and ...
6
votes
2answers
8k views

Newton's method to solve cubic equations

I have used the Newton-Raphson method to solve Cubic equations of the form $$ax^3+bx^2+cx+d=0$$ by first iteratively finding one solution, and then reducing the polynomial to a quadratic $$a1*x^2+b1*x+...
6
votes
1answer
6k views

Tkinter file searching program

This is my first relatively big program. First it shows an askdirectory() screen to get the path. It gets all subfolders of that path and appends them to a list. It ...
4
votes
1answer
2k views

Python converter: number-to-English - Project Euler 17

So I wrote this function to convert a given number to its interpretation in the English language as part of the Project Euler exercises. It works fine, but I sense that it's rather sloppy and ...
6
votes
3answers
744 views

Performance of modular square root

Here's Project Euler problem 451: Consider the number \$15\$. There are eight positive numbers less than \$15\$ which are coprime to \$15\$: \begin{align*} 1, 2, 4, 7, 8, 11, 13, 14. \end{...
3
votes
1answer
20k views

Reading columns and rows in a .csv file

I have some data in a .csv file, which looks roughly like this: ...
9
votes
2answers
9k views

Python Port Scanner

This is only my third Python script. Be brutal with me. Any tips, tricks, best practices, or better usages would be great! ...
1
vote
1answer
7k views

Fastest way for working with itertools.combinations

I need to speed up the function below: ...
4
votes
1answer
377 views

Partial data reading implementation

I'm trying to learn Python and am working on a simple Tiled Map Format (.tmx) reader as practice. So as to not post too much code at once, I'm only publishing the ...
4
votes
1answer
11k views

struct.unpack on a bytearray that works under Python 2.6.6, 2.7 and 3.3?

Given the test code: import struct buf = bytearray(b'\xef\xf8\t\xf2') number = struct.unpack("<I", buf)[0] How do I cleanly make it work both under Python 2.6 ...
2
votes
1answer
276 views

Reading Multidimensional arrays [closed]

I am building a cypher program which uses a matrix of numbers and letters. A message is encoded according to the row and column each letter of the message is found in the matrix. I am trying to find ...
3
votes
1answer
902 views

Calculating potential Chess moves

I started a Chess in Python for fun. I learned Python in my free time but I've been doing it for a while. The code works but I just want to know if there's anything non-pythonic in my code. The ...
5
votes
2answers
4k views

Python Script to Search PirateBay

I've written a very basic Python 3 script to search ThePirateBay. Since the tracker doesn't have an API, I had to parse the HTML using BeautifulSoup. I'd like to get some reviews, I'm pretty sure the ...
4
votes
3answers
5k views

Drawing stars around the center of the screen

I have an homework as follows: Write a program where you enter from the keyboard a number n. Then n stars are drawn onto the screen, circling around the center of your screen. You can assume ...
5
votes
2answers
124 views

Copying data to a .txt, but making it look nice?

This is probably horribly sloppy, but here it is! This is a section from a large (imo) GUI program I am making. The below code is what triggers when a specific button is pressed. ...
4
votes
4answers
2k views

Rock paper scissors

I've started learning Python recently and I wanted to test myself. So, can you tell me how many I would get out of 10 and how I could improve my future coding? ...
5
votes
1answer
102 views

Organization of complex empirical equations

I am working on coding up a set of models that are based on empirical models. These models tend to be quite complicated. In some cases, the logic used by the equations makes it impossible to compute ...
1
vote
2answers
14k views

Taking the sum and average of the keyboard inputs

I have an assignment as follows: Write a program where you can enter from the keyboard up to 10 integers. If the number entered is equal to -99, stop reading numbers from the keyboard and ...
2
votes
4answers
30k views

Printing a rectangle

I have an assignment as follows: Write a program which reads from the keyboard two integers n and m, and a character c from the keyboard. This program should define and call a function: print ...
2
votes
1answer
3k views

Drawing a table in Python3 [closed]

I have created a module to draw text tables. The relevant parts are below and here's the full code for txtable). ...
-2
votes
1answer
1k views

Best way to print the value of a variable? [closed]

Which of the following is better coding style and why? print("We have x = %i" %x) print("We have x = "+str(x))
5
votes
1answer
452 views

Script for concatenating delimited text files

I need to concatenate a bunch of delimited text files. In the process, I need to add a new column to the data based on part of the name of one of the directories containing each file. The script works,...
3
votes
2answers
5k views

Find scrambled words within word list

I'm just getting started with Python -- completing a simple exercise from a practice website. My code works -- just looking for feedback on better ways to achieve the goal. Goal: Find the ...
2
votes
2answers
1k views

How to make this random number game better?

I'm a newbie trying to teach myself Python. Could somebody tell me if there is a better way to write this? I am also curious as to whether or not there is anything I should not do. This code does ...
0
votes
2answers
619 views

How to enumerate the internal nodes and leaves of a tree more elegantly?

Might there be a simpler way to write this code? I'd like to learn to write code more efficiently. ...
2
votes
1answer
124 views

How to turn this working A/B optimization program into more pythonic code?

I have a working solution for the given problem of A/B Optimization, but you as an experienced Python (3) developer will agree with me, that this solution is not very pythonic at all. My Question here ...
6
votes
2answers
7k views

Returning a list of the values from the binary tree

I want to return a list of the values from the binary tree. Is there a shorter and more efficient way to write the method for numbers? ...
14
votes
2answers
8k views

Unbeatable Tic-Tac-Toe program seems difficult to read

I've made an unbeatable Tic-Tac-Toe in Python 3.3. While it truly was unbeatable, it was an eyesore to look at and nigh impossible to read. That code is here. I have since then optimized it for ...
8
votes
1answer
3k views

Subscriptable/Indexable generator

I'm not a Python developper, but I enjoy programming with it, and for a project I wanted to have generators that I can easily index. Using python's slice model is obviously the way to go, and here's ...
2
votes
1answer
69 views

Checking user input for boxing sim engine [closed]

I am creating a simple Boxing sim engine and have got things working fairly well. A few months ago I was instructed to avoid copy and pasting code and to try and "conserve my logic". Anyways, I feel ...
4
votes
3answers
11k views

Rock, Paper, Scissors game assignment

This is an assignment that I have already turned in. It works great, but I was wondering if there are any flaws in the code, or how to write it in a more pythonic way. ...
3
votes
1answer
952 views

Object Composition

So I have this Pygame 3.3.2 code of 2 classes. I tried to make it as simpler as possible, but ofcourse to show the problems I have with thedesign. ...
4
votes
1answer
214 views

Creating a game with rectangular shapes

I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to ...
5
votes
4answers
10k views

Building a number pyramid

I have been working a number pyramid program. This is a question from Y. Daniel Laing's Introduction to programming using Python (which is based on Python 3.2). The question is from chapter 5, and it ...
11
votes
6answers
16k views

“Multi-key” dictionary

I was making a relatively large-scale project in Python as a learning experiment, and in the process I found that it would be useful to have a map (or, in Python, I guess they're called dictionaries) ...
4
votes
1answer
603 views

Batch program to xcopy from host PC to remote destination with multi-processing

This is a batch program to xcopy from host PC to remote destination with multi-processing. Kepler, Python-3.x are my environment. ...
5
votes
2answers
10k views

Simple age converter

I want you to pick my code apart and give me some feedback on how I could make it better or more simple. In my opinion this is the best code I have written, being that I'm new to programming. The ...
3
votes
1answer
1k views

Python infinite product generator

I have the code below to get an infinite generator of the products of an iterable (e.g. for the iterable "ABC" it should return A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC, AAA, AAB, AAC etc. ...
3
votes
3answers
42k views

Python calculator script

Are there any ways to make this calculator script for Python better or simpler? ...
1
vote
1answer
13k views

Super simple spam program

x = int(input("Choose the number of times you want to spam. ")) y = input("What message do you want to spam? ") w = x + 1 for i in range(1,w): print(y) Any ...