Leon Davis

@LeonDoesCode (380)
uh, i don't know...
Advice for self-learners: How to teach yourself, find motivation and project ideas

What a great read! Can't wait to see what you write about in the future. Stay positive everyone!

Pokemon Battling Simulator
posted to Share by JimBob5

Can I suggest https://pokeapi.co/. You will need to rewrite quite a bit, and also do a few requests, but it could be worth it. All the stats, alsong with a lot of other information is there.

Love the game as it is though, can't wait to see you add more!

Games in Love2D
posted to Tutorials by LeonDoesCode

@jpmartel98 sorry for the long wait.

did you use keyboardisdown or keyboard.isDown (capitalisation is importatant).

Commenting Your Code
posted to Tutorials by LeonDoesCode

@Highwayman I try, I try. Lul.

PyRPG Editor
posted to Share by Tru_Dev

Looking good! Can't wait to see what gets added!

pip isn't working properly
posted to Ask by zealsham

I believe that the Package Manager (which uses poetry) is currently conflicting with pip. So you may have this problem a lot. A quick fix is to just go back into the Package Manager and install the Package again.

Help please
posted to Ask by LukeShomper

You have:

while True:
  x = 30
  y = 50

This will make it so that your x and y never change as the become the default every update. Move this to before the while loop, you should be able to move then.

Game in Python
posted to Tutorials by LeonDoesCode

@Highwayman At least I'm not the only one lul.

App of the Week #1
posted to Announcements by PDanielY

Nicely done!

How to use streamlit in Repl.it
posted to Ask by NicolasRemond

@NicolasRemond I switched out subprocess for os like so:

import os
os.system("streamlit run app.py")

When you run it, you now get links in the terminal. Is that what you wanted? (The links are dead by the way).

How to use streamlit in Repl.it
posted to Ask by NicolasRemond

You can still run shell commands in Repl. So you can use subprocess to get the result you are looking for. You can move the code you have in main.py to a new file, and then use the main.py file to run the commands which will run streamlit`.

help moiii
posted to Ask by ayasin31

To round a number in Python, all you have to do is wrap int() around it. E.g

print(int(5.580))
print(int(input("Enter a float: ")))
images in repl
posted to Ask by MackRamirez

If your image is on your computer, you can drag it into the place where all your other files are. The paths will work the same as normal (if your image is in a imgs folder, then you would access it using imgs/{file-name}.

If it's on the internet, you can copy the link to it and use that as the src value.

Coding Music
posted to Ask by Rileygamer21

I listen to a lot of LoFi personally. It's more of a background music so it doesn't take your attention away from coding. I recommend The Jazz Hop Café for good LiFi collections.

Saving Variables in Python
posted to Tutorials by LeonDoesCode

@theangryepicbanana sorry for the obsessive posting. Will do. (I only posted three tutorials if you check my profile).

Game in Python
posted to Tutorials by LeonDoesCode

@CodeABC123 and that is the perfect example of why you don't forget to "View All" comments.

Game in Python
posted to Tutorials by LeonDoesCode

@CodeABC123 I would love to, but I no longer have this repl.

Game in Python
posted to Tutorials by LeonDoesCode

@JayRoy what error are you getting?

Game in Python
posted to Tutorials by LeonDoesCode

@JayRoy no problemo.

How do I make a random number in python?
posted to Ask by ThePuzzlerThree

@ThePuzzlerThree math is part of the standard libaray, so all you have to do is:

import math

But for random integers, you can use:

from random import randint
num = randint(0, 100)
Online Multiplayer in NodeJS
posted to Tutorials by LeonDoesCode

@dcbriccetti I do indeed, here it is.

ANSI Escape Codes in Python
posted to Tutorials by LeonDoesCode

@theangryepicbanana true, true. Just though I'd also show how to make a little library in Python as the ANSI Codes by them self didn't seem like they could do one tutorial. Thanks!

Game in Python
posted to Tutorials by LeonDoesCode

@JohnBerliner2 Glad it was helpful! Thanks for mentioning this, I forgot to but will add it now.

How to save a register in python?
posted to Ask by AsgardianoBR

May I link you to a tutorial. The tutorial covers how to save variables to a JSON file, you can then also use this tutorial to hash the passwords and save them securely.

The reason that I'm suggesting JSON here, is that I've been having problems with databases without using client server stuff. This is really that sort of thing. If you know how to do this then I'd suggest using an external service, or creating an client and sever Repl, so that you can manage login details.

But for small pieces of code, with few login details that DO NOT link to your real details, then a JSON file will do the job. You can also use a .env file if it has to be secure. Only you can see this file and its contents, so "sensitive" information can go in it.

Files
posted to Ask by Prof_Baldi

@Prof_Baldi Gald it helped you. Also, there is one more way to access them. You can specify what you want to import, like so:

from test import writeText
writeText("Hello World!")
Files
posted to Ask by Prof_Baldi

If you create a new file, such as test.py. You can access the file like normal. You can use:

import test

To use the functions, classes and variables from the test file.

E.g.

test.py

def writeText(text):
  print(text)

main.py

import test
test.writeText("Hello World!")

You can also import all the functions, classes and variables using the wildcard statement *:

main.py

from test import *
writeText("Hello World!")
finding the largest number in an array
posted to Ask by DamienVapes

@theangryepicbanana That is why I also included the second part (after "This is like calling:"). It explains what that function is similar to calling, and how that function works.

However, I see your point, will try to not do this in future. Thanks for the feedback!

finding the largest number in an array
posted to Ask by DamienVapes

In JavaScript, you can use the Math.max.apply() function to do this, like so:

// Will return the largest number
function getLargestNumber(numbers) {
  // Takes in Math and the array of numbers, and returns the largest one
  return Math.max.apply(Math, numbers);
}

// Or
function getLargestNumber(numbers) {
  return Math.max(...numbers);
}

This is like calling:

function getLargestNumber() {
  // This function returns the largest number from all the numbers parsed in
  return Math.max(5, 7, 3, 2);
}

You can also do this with Math.min too.

Hope this is what you were looking for!

Embedded Code
posted to Ask by mamamia5x

You can press the "Open in New Tab" button above the Console to the right. This will open it in a new tab for you to use it in. If you all do this, then you will be running separate instances of it.

Inserting text in print()
posted to Ask by Qwirrr

You can use the .format() function like so:

a = 12
b = 6
print("{} + {} = {}".format(a, b, a+b))

# Or
a = 12
b = 6
print("{a} + {b} = {c}".format(a=a, b=b, c=a+b))

# Shorthand
a = 12
b = 6
print(f"{a} + {b} = {a+b}")

The f in front on the last one, specifies that the string is going to be formatted, so you can add the values inside the {}.