Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

-2
votes
0answers
11 views
3
votes
2answers
137 views

“Guess my Number” game in Python (2.7.9)

First time posting to Code Review. Just looking to get some advice on how I can write better code. I found the following exercise for a "Guess my Number" game on DaniWeb, but the linked source code ...
-3
votes
1answer
59 views

Parsing JSON in one go using state machine solution

I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
-4
votes
0answers
13 views

Create a while loop that repeats letters in the function [closed]

I am trying to get letters in the code to print out like 'aabbcc' if you typed 'abc' into the code. Right now it only prints the first letter, how do I get it to print all of the letters that are ...
1
vote
1answer
30 views

A simple log that tracks hours worked and and a python script that calculates wages

I wrote a simple Python script that will calculate income for a given month and hourly wage by parsing the contents of a log file. The instructions for how to use it is in my GitHub account here. The ...
-4
votes
0answers
10 views

How can I scan a string of very large length [closed]

I am using s = raw_input() to read the string but not getting right answer for very large len(s) ? Please help me with that. ...
1
vote
0answers
16 views

Python: Recursion Practice

Problem: Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length. sub_sandwich("catcowcat", "cat") → 9 ...
-2
votes
0answers
16 views
1
vote
1answer
39 views

SKlearn automate data pre treatment

I want to make a simple wrapper for sklearn models. The idea is that the wrapper automatically takes care of factors (columns of type "object") replacing them with ...
2
votes
3answers
19 views

Longest Collatz sequence in Python

I came across this problem: The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) ...
-1
votes
2answers
77 views

JSON string parsing

I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
4
votes
2answers
52 views

Python command-line Tic Tac Toe for two humans

I’d love some feedback on this human v. human, tic tac toe game I wrote in Python 2.7.10. I’d love to hear your thoughts on optimization and making the code simpler and more “pythonic”. Also, I’m ...
2
votes
2answers
53 views

Random positioning and movement of a rabbit on a table

I was inspired by this: If you would put a rabbit randomly on a circular table with radius r= 1 meter and it moves 1 meter in a random direction, what is the chance it won't fall off? I ...
3
votes
1answer
62 views

Remove last odd number from number list in Python

The simplified question is: Given a list of numbers, write a Python script that will remove the last odd number from the list. One of the challenges is if the last odd number appears multiple ...
4
votes
1answer
61 views

Downloading files using Python-requests

I wrote a Python script to download files using multiple (source) IP addresses -- kindly suggest any improvements. ...
3
votes
2answers
94 views

Simple PIN Locker in Python

I am fairly new to Python but I have been improving, and I wanted to try writing a simple program that simulates locker with multiple chambers (4) for storing "objects". I recently used lockers at a ...
6
votes
1answer
51 views

Stack Exchange API Python library

I wrote a package a few years ago to make my interactions with the Stack Exchange API more straightforward. I've maintained it over the years and used it in several scripts I've written that interact ...
9
votes
2answers
1k views

4chan Tripcode Explorer in Python

Background information for those of you who don't know what 4chan tripcodes are: Via Wikipedia: A tripcode is the hashed result of a password that allows one's identity to be recognized without ...
1
vote
1answer
50 views

Selecting a random student from a class list

This selects a random student from a class list, stored in a .ss file: ...
8
votes
1answer
99 views

Extending the functionality of lxml.etree

I wrote a class to slightly customize the behavior of lxml.etree.ElementTree and I use it quite extensively. It works great, but there are a few methods that I'm ...
4
votes
2answers
65 views

Printing letters in order like a pyramid

There is this hackerrank question, where we need a rhombus of letters. As to my opinion it can be viewed as some fractal, or similar logic. Well I solved the question, but I am obviously disappointed ...
4
votes
2answers
58 views

Custom array indexing

Note that this code is not going to be used for anything, it's more of a thought experiment. I've been seeing a lot of NumPy code lately and noticed that they use a custom indexing process, presumably ...
3
votes
3answers
68 views

Creating and manipulating FITS files

I wrote a program that manipulated data from VLA observations and created FITS files to be used in creating spectral energy distributions of high redshift radio galaxies. I really tried to be as ...
5
votes
3answers
324 views

“Researcher Hatim is right or wrong” challenge

I wrote a program to solve a problem, I am not so good in python so want help to find areas where this program can be improved or simplified and readable too:- I got this problem in a code challenge ...
4
votes
1answer
46 views

Tic-Tac-Toe in Python 2.x

This is a class called Board which handles the tracking and checking of the state of the game. self.board is a dict of ...
2
votes
2answers
99 views

Password Trainer v1.0 - Helping you learn a new password

There are two reasons why many people choose weak passwords over stronger, more complicated ones: They don't know that their passwords are insecure They don't want to change to a better password ...
2
votes
1answer
44 views

Functional Scrabble Word Score

Homework: Write a function to score a scrabble word. values is a global dict formatted as values = {'a': 1, 'b': 3,...} The ...
4
votes
3answers
217 views

Word frequency counter

I recently took a self-assessment question to assess my Python ability for an online class. The problem was to return the frequency of a word occurring, as part of a tuple. Implement a function ...
3
votes
2answers
45 views

Finding a pair of words from two files with a particular MD5

I have two txt files. Both contain 60k+ words in a list. I put together some code to loop through each file and concatenate the strings ...
5
votes
2answers
59 views

Chen prime finder

I've written a programme to find Chen primes. A Chen prime p is a prime number where (p + 2) is either also a prime number or has two prime factors. I've got it working to the best of my knowledge: ...
4
votes
4answers
578 views

Decode Cæsar Cypher by Checking all Keyspaces

This function produces a decoded string, decoded, for all keyspaces against a given cæsar cipher ciphertext. Punctuation is not changed and ...
4
votes
3answers
97 views

Python Hash Table Implementation

I'm attempting to implement a basic hash table in Python using only lists. any tips would be appreciated (including better hash functions). I intend this to handle collisions with separate chaining. ...
3
votes
1answer
58 views

Building thermostat state machine in Python

I used a Raspberry Pi and Adafruit LCD with buttons to build a small thermostat for my house. This is the hardware I used to you can imagine how the button and the code work: ...
3
votes
3answers
74 views

Simple multiplication quiz

I am learning Python, and would like to learn how to make this code simpler and easier to read. Things I am hoping to learn: What variables might be appropriate? How can I make it simpler? Is there ...
1
vote
2answers
50 views

Replacing data in a .csv file

The code works well and does what I intend for it to do. In essence, it opens a file referenced as 'resource'. This is a .csv file. I then searches for the keys in the dictionary and for each key that ...
2
votes
2answers
66 views
37
votes
6answers
3k views

Accurate email syntax validation (no seriously)

So a friend happened to show me how odd and specific the general email syntax rules are. For instance, emails can have "comments". Basically you can put characters in parentheses that are just ...
2
votes
2answers
47 views

Count overlapping substrings

I'm looking for feedback on the actual logic of this simple Python 2.7 script. The automated grader passed it, but I expect it could be make more 'pythonic'. It was written for homework, and some of ...
3
votes
2answers
107 views

Pixelating black and white images

I am doing a function that pixelates black and white images. The function must be called pixelate(img, (pixel_width, pixel_height), mode). The parameter ...
4
votes
2answers
94 views

Gilbreath's conjecture in Python

I've written some code for testing Gilbreath's conjecture in python (2.x). The conjecture was shown (in the 90s) to be true up to n=1012. My code uses the primesieve module to quickly generate primes ...
3
votes
2answers
53 views

Compare lines in 2 text files with different numbers of fields

This is the (hopefully) final version of my script for my file comparison problem mentioned previously in two posts on Stack Overflow (here and here). I have come up with the code shown below, which ...
10
votes
4answers
839 views

Generate set of random numbers and remove lowest

I'm learning some Python with my kids, and we're making a program to generate D & D characters from user input. One portion of the code is to generate stats, which are a set of six numbers where ...
1
vote
0answers
53 views

Predicting a win/loss given prior game stats

The project: create a model that can (somewhat) accurately predict a win/loss given prior game stats. Wanted a review of code in general, in particular my use of the ...
1
vote
2answers
29 views

Find available ports on localhost

I'm writing code to find the available ports on 127.0.0.1. I'd like it to be faster, but it's functional now. ...
7
votes
3answers
50 views

Accessing files in a child directory in Python 2.7.x

I have written the below script for use in Python 2.7.x. In essence, I want the script to access a folder contained within the directory the script is and then add all files contained within to a ...
3
votes
2answers
82 views

Console animations

I'm a coder who's relatively new to Python and I wanted to spice up my console applications a bit by making animations. The code I've written works perfectly, but I just wanted to know if it was good ...
0
votes
2answers
44 views

Choosing different Version of a model

Is there anyway to improve with how this code is structured into functions? Is the coding style compliant, and what can be improved beyond this? ...
9
votes
2answers
698 views

Making a Battleship Game

I'm making a Battleship game using python 2.7. However, how to make it is not currently my issue. The main aspect that I'm asking about is the style and method of making the code. Am I following ...
3
votes
1answer
78 views

Prove that the graph is a valid tree in Python

I recently solved this leetcode problem: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges ...
8
votes
2answers
141 views

Small text-based game

I am brand new to coding in Python, and programming in general. I have picked up the Learning Python book and have been slowly making my way through it. I decided that I would try to implement what I ...