Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

1 vote
Accepted

A game where the player guesses the computer's number

Possible bug When I run the code, and it executes this line: slow_print('You\'ll have ', str(guesses - 1), ' guesses to get it.') the code exits with an error. My ...
toolic's user avatar
  • 3,516
3 votes

Python - Text-based game about an escape room

The answer provided by @toolic is already very good. I would add two comments. Cyclomatic code complexity In your main while loop you have a lot of nested ...
Attack68's user avatar
  • 311
2 votes

Python - Text-based game about an escape room

File name This line implies that you named a file classes.py: from classes import * The file name is too generic. Give it a ...
toolic's user avatar
  • 3,516
3 votes

A rock-paper-scissors game using HTML & Javascript

Hooked on a Feeling In @Alex Answer Is there a way to implement this, so that such an extension would be simple? and OP's comment: functions that are essentially doing the same thing ... figuring ...
radarbob's user avatar
  • 7,599
4 votes

An Implementation of UNIX wc shell utility

...
user673679's user avatar
  • 11.8k
2 votes

A rock-paper-scissors game using HTML & Javascript

What you should ask yourself: If you wanted to extend this to "rock, paper, scissors, lizard, Spock", how much code would you have to change? Is there a way to implement this, so that such ...
Alex's user avatar
  • 41
6 votes
Accepted

An Implementation of UNIX wc shell utility

The code looks very nice; it's consistent, nicely organized, and global variables have been avoided. There are some minor things that could be improved though: Naming things Avoid unnecessary ...
G. Sliepen's user avatar
  • 57.1k
5 votes

code format and steps web scraping using beautiful soup

I would like to see a few things generally to make this code easier to work with in future. Rather than have main do all the work I would have ...
El Ronnoco's user avatar
6 votes

Guess the number game with an easy and hard mode

meaningful identifiers You wrote: def is_number(technical_number): ... def is_number_repetition(): ... def more(): ... def more_user(): ... You elected not to ...
J_H's user avatar
  • 27.5k
5 votes

code format and steps web scraping using beautiful soup

Since your df is just using a default range index, I suggest ignoring the index column with index=False when saving: ...
tdy's user avatar
  • 1,350
7 votes

code format and steps web scraping using beautiful soup

I agree here is little to review. Two tips though: use requests.Session() and always check the status code. If it's not 200, the request has not succeeded. You should not proceed with parsing. In the ...
Kate's user avatar
  • 6,753
2 votes

Generating millions of hashes sha256 and random String in Java

Simply, you are using one thread. Use parallel threads for generation. For example: ...
utrucceh's user avatar
  • 121
4 votes

Euler - Largest Palindrome Product in Java

Unnecessary Boxing Integer is a heavy weight Object in Java, with exactly the same range as the lightweight ...
AJNeufeld's user avatar
  • 33.7k
3 votes

Euler - Largest Palindrome Product in Java

One additional remark: Method and variable naming Try to name a method in such a way that this name tells you what the method achieves. That's an art and something that typically improves with ...
Ralf Kleberhoff's user avatar
0 votes

R Script to forecast volatility of monthly crude oil prices using GARCH

Shadowing It's bad practice to shadow built-ins: forecast <- forecast(ar1, h = 12) You should choose another name to store the forecast output, e.g.: ...
tdy's user avatar
  • 1,350
4 votes
Accepted

Collatz conjecture plots (python)

Since there is only 1 argument ... what I cannot understand is why it doesn't put collatz_values on the x axis. That's just how matplotlib implemented it. If you ...
tdy's user avatar
  • 1,350
8 votes
Accepted

Euler - Largest Palindrome Product in Java

Avoid keeping State in a static variable / Minimize the scope of variable The advantage of not doing so might not be immediately obvious in this case because it's a sort of one-shot code (in a sense ...
Alexander Ivanchenko's user avatar
3 votes

Diamond printing code Kata

I'm not going to use Base in my answer, because I don't need to. I'm sure you can adapt it to that library. If we use ...
Chris's user avatar
  • 233
2 votes
Accepted

Blackjack optimization in python (Update)

I tried to clean your code, removed unused variables, and made dealer money infinite and deck creation faster. Revising your it saw a big mistake: Player and Dealer used a different deck and fixed it. ...
AsrtoMichi's user avatar
4 votes

Plotting Collatz conjecture values - Python

Integer arithmetic seed = seed/2 takes the value of seed (initially an integer) and divides it by 2, and stores the result as a <...
AJNeufeld's user avatar
  • 33.7k
3 votes

Plotting Collatz conjecture values - Python

identifiers The literature tends to speak of "values" generated by the \$3n+1\$ process. A "seed" is used to start the process, and we see successive values grow from there. It is ...
J_H's user avatar
  • 27.5k
6 votes
Accepted

Plotting Collatz conjecture values - Python

Note how you're manually repeating the number of seeds (1500): colors = plt.cm.bwr(np.linspace(0, 1, 1500)) for i in range(1, 1500): ... That's always a good ...
tdy's user avatar
  • 1,350
0 votes

My first code: Blackjack game

Probably best to just call it a deck and the function draw. We use verbs for functions. The index ...
Maarten Bodewes's user avatar
3 votes

Display summary statistics about Discord messages

Yes, as you have indicated, the very first step should be to split your code into dedicated modules. Almost all of your methods are used only once. A very natural split could be to encapsulate those ...
Peter Csala's user avatar
  • 9,159
3 votes

Tic-tac-toe OOP Minimax Algorithm

if 0 in self.board: return None There are board positions where a win is no longer possible but there still are open spaces. Continuing playing at this point ...
Cris Luengo's user avatar
  • 5,673
3 votes
Accepted

Tic-tac-toe OOP Minimax Algorithm

it would be nice to be able to speed it up a bit. To properly study that, I recommend you scale up from \$3 × 3\$ to \$n × n\$. mutable arg idiom ...
J_H's user avatar
  • 27.5k

Top 50 recent answers are included