r/pythonhelp • • Oct 22 '22

Anyway to call on a variable outside of a function?

0 Upvotes

So I have to make a game that involves 3 separate functions, one for calculations(), it just calculates random numbers. Another for user_guess(), displays the numbers and asks the user to guess. And lastly for the main game itself: main() , where it gives the user a score and repeatedly asks the user questions utilizing the other two functions.

So here’s my problem; within user_guess() is a user input variable. But because it’s localized to that function I can’t use it to verify if the user input is equal to calculations(). The user also needs to type ‘q’ to end the game. Does anyone know if there is any work-arounds to this?


r/pythonhelp • • Sep 13 '22

Can't use Bin method, but need to accomplish what it does

0 Upvotes

For a Lab I need to convert an int into its binary representation, however I am not allowed to use the bin method. Whenever I load a string with this data it automatically converts to displaying my added 0b then the original int value. Any suggestions?


r/pythonhelp • • Oct 08 '22

Where can I learn by doing Python projects?

0 Upvotes

I know how to code... not expert in Python. I've only dabbled.

I'm getting bored watching videos. I've tried codeacademy and don't like reading from a screen.

What I'd love is ready made projects. I've seen a few places, but I thought I would ask here for some recommended pointers.

Thanks.


r/pythonhelp • • Oct 19 '22

SJQ injecting sqlite

0 Upvotes

So I'm creating a basic website with Flash SQLAlvhemy and SQlite because I have to preform a SQL injection attack with wfuzz for a school project, but while I was reading the documentation for SQlite it said the library didn't allow for SQL injection attacks to be preformed against the database. So is the documentation wrong? Should I use a different database?


r/pythonhelp • • Oct 15 '22

Getting count of string

0 Upvotes

Get Counts of (A, An, The) in a paragraph. The article should be given as input while running the script.


r/pythonhelp • • Jan 30 '25

For anyone else struggling to set up a virtual environment - here's what worked for me

0 Upvotes

So I don't know if this is specifically an issue with Python on Linux, or maybe Python on Arch. In any case, I noticed a lot of people had similar issues as me, and a lot of stuff I tried was outdated, or maybe didn't work on my distro.

My case: I thought I'd set the global Python version with `pyenv global 3.9.19` (which I've since learned is apparently a no-no, at least on Arch), but later found that the command never actually worked: `python --version` would keep reporting the newest Python instead of 3.9. This turned out to be a problem when Arch forced the newest version of Python on me, and broke compatibility with some dependencies for an app I often use.

I tried a number of guides for setting up a Python environment, only to notice my terminal kept reporting the newest Python instead of the version I wanted. Sure enough, when trying to run stuff in my virtual environment, I'd get the same errors as when using the newest/global Python.

Turns out, a number of guides fail to mention that - at least in some cases (maybe on Arch) - _virtual environments can be picky about the directory you install them in._ The virtual environment kept using the newest Python when I tried installing it in a desktop folder, but worked properly when I set it up under `~/.venvs/`

Deciding that 3.12 would be good in my case (with my new info), and after installing 3.12 via my package manager, this is what worked for me - make sure to use `bash` (my terminal is set to use fish):

```python3.12 -m venv ~/.venvs/venv312

source ~/.venvs/venvs312/bin/activate```

Once I used the `source` command, I noticed my terminal reported that it was using the version of Python I wanted, and I was able to use Python commands normally. Speaking of which, I HIGHLY recommend trying out `pipenv` if you haven't - it basically tries to detect and install all the dependencies for you. 😉 I'd also suggest setting up a bash script to start your venv, and maybe any apps you have it specifically set up for.

Quick aside, I've noticed there are two camps: One (often asking questions) who think that virtual environments are needlessly complicated, and another (often answering questions, but inadvertently leaving important details out) claiming virtual environments are super simple. I'd say... maybe simple once you figure them out, but it can be a pain getting there. 😂 (Like with many things in tech, IMO.)

And yes, I'm going to clean up my unneeded Python installs.


r/pythonhelp • • Jan 24 '25

Trying to get this code to count up or down by 1 and have the turn # always go up by 1.

0 Upvotes

import random
from random import randint

#the list of all the numbers 1-120 we will be referencing
random_numbers = []
random_numbers.extend(range(120))
random_numbers.sort()
starting_number = random_numbers.index(randint(0,120))

#the numbers the student knew
known_numbers = []

#the numbers the student did not know
unknown_numbers = []

#assigning variables
forwards = 1
backwards = -1
num_count_up = 1
num_count_down = -1
plus_one = 1
minus_one = 1

#first number randomly given, removed from list, moved to other list
print(random_numbers[starting_number])
random_numbers.pop(starting_number)
known_numbers.append(starting_number)

plus = (starting_number + 1)
minus = (starting_number -1)

def plus_one(a,b):
    return a + b
def minus_one(a,b):
    return a - b
    
turn_count = 0
for i in range(1):
    if turn_count < 120:
        x = plus_one(turn_count, 1)


def num_count_up():
    print("Turn: " + str(x))
    count_up_ans = int(input("What number comes next? "))
    if count_up_ans == (random_numbers.index(plus)):
        print("Correct! " + str(plus_one(starting_number, turn_count)))
        known_numbers.append(random_numbers.index(plus))
    else:
        print("Sorry, it's " + str(random_numbers.index(plus)) + ".")
        unknown_numbers.append(random_numbers.index(plus))
    return num_count_up()
    
def num_count_down():
    print("Turn: " + str(x))
    count_down_ans = int(input("What number comes next? "))
    if count_down_ans == (random_numbers.index(minus)):
        print("Correct! " + str(minus_one(starting_number, turn_count)))
        known_numbers.append(random_numbers.index(minus))
    else:
        print("Sorry, it's " + str(random_numbers.index(minus)) + ".")
        unknown_numbers.append(random_numbers.index(minus))
    return num_count_down()
    
#Using RNG to determine if counting forwards or backwards
#determines which function to call
def up_or_down(a, b):
    import random
    random_num = random.randint(a, b)
    if random_num == a:
        print("Let's count forwards!")
        print(num_count_up())
    elif random_num == b:
        print("Let's count backwards!")
        print(num_count_down())
    return up_or_down(a, b)
    
while len(unknown_numbers) != 10:
    print(up_or_down(0, 120))
if len(unknown_numbers) == 10:
    print("Too many tries. Let's practice later.")
    print("Here are all of the numbers you should study: " + str(unknown_numbers))


#2 variables
#conditional statement
#loop
#function 1
#function 2
#2 datatypes
#list

r/pythonhelp • • Sep 05 '19

Please help, I'm in an intro to programming class and I'm stuck on a question.

0 Upvotes

I've googled everything I could think of with no good results, this is the question:

For this programming exercise, write a simple script that will ask the user to input an integer value, wait for the user to enter the value, and then display the entered value back to the terminal. After that, the script should display two (2) times the value entered to the terminal as well.

Example script output (input in bold):

Please enter an integer: 42 You entered 42 Twice that value is 84

Please help, I don't just want the answer. I'm looking to understand it. Any help is much appreciated. Thanks


r/pythonhelp • • Oct 19 '19

Python Help

0 Upvotes

Can someone please help me with some python questions. I will introduce the questions through via messages so message me and help me if you can. Some general information of the questions is that they are hard so only if you can really do python please let me know if you can help me.


r/pythonhelp • • May 15 '18

I am an ablsolute noob, but why does this not work? It says the class isn't defined.

0 Upvotes

print("Welcome to the Wonderful World of Text Adventure") print("Please choose a class to play as. Your choices are: Wizard, Warrior, or Archer") action = input("> ") if action == "Wizard": print("You are now a Wizard") Wizard == True elif action == "Warrior": print("You are now a Warrior") Warrior = True elif action == "Archer": print("You are now an Archer") Archer = True input("You live in a village on the coast of a large kingdom") input("As you walk by an old woman walks up to you. She says her grandson has been stolen by orcs while picking blackberries") if Wizard: print(" Old Woman- I have heard you have great magical powers, and it would be nice if you could save my grandson from those nasty orcs.") elif Warrior: print(" Old woman- I have heard you are very skilled at combat, would you go and save my grandson from thase wretched orcs.")

input("If you wish to leave, press enter")


r/pythonhelp • • Oct 16 '19

Help I have no idea how to do this!

Post image
0 Upvotes

r/pythonhelp • • Feb 21 '20

Error with cv2 and OCR

0 Upvotes

ok so I've been trying to take an image, edit it in open cv, create a temporary file to apply ocr, then print the text outputted. I keep getting

Expected Ptr<cv::UMat> for argument '%s at the line with cv2.write.

This is the code

import pytesseract

import cv2

import os

from PIL import Image

# load the example image and convert it to grayscale

gray = cv2.imread("download.jpeg", cv2.COLOR_BGR2GRAY)

gray = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY)

#gray = cv2.medianBlur(gray, 3)

# write the grayscale image to disk as a temporary file so we can

# apply OCR to it

filename = "{}.png".format(os.getpid())

dirname= "test"

os.mkdir(dirname)

cv2.imwrite(os.path.join(dirname, filename), gray)

# load the image as a PIL/Pillow image, apply OCR, and then delete

# the temporary file

text = pytesseract.image_to_string(Image.open(filename))

os.remove(filename)

os.remove(dirname)

print(text)

# show the output images

cv2.imshow("Image", image)

cv2.imshow("Output", gray)

cv2.waitKey(0)


r/pythonhelp • • Apr 29 '24

Byte addition in hex format -with PYTHON

0 Upvotes

I have 50 rows with hex data. Each row has 5 bytes in hex format. As an example of two rows of hex values are below:
[92cb2004fe],
[210c1003f3]
How do I do bitwise addition for each byte. Say, add first 3 bits of a low strength bits and last 2 bits of high strength bit. AS an example, 92 =1001 0010, I would like to add 010(first 3) and 10. I would like to achieve same addition for all the 5 bytes in each row.

Then I would like to save as CSV file as integer values.


r/pythonhelp • • May 03 '24

помогите новичку

0 Upvotes

я только изучил основы пайтон, как начать работать? или что вообще делать дальше?


r/pythonhelp • • Apr 15 '24

Will some-one be willing to assist me with a project I am busy with?

0 Upvotes

I need assistance with my code. I would like to get help or some-one's opinion on the matter if I with my skills will be able to do it myself or if I will need further help from other people that knows more about coding than what I do. Just please keep in mind I am 19 and don't have much experience with coding so. Send me a pm or add me on discord : dadad132.


r/pythonhelp • • Apr 10 '24

Any needed assistance in python?

0 Upvotes

Looking for academic help? We provide a wide range of services to support your academic and professional needs. Our offerings include:

  • Web Development

  • Essay Writing

  • Game Development

  • Assistance with Online Classes

  • Matlab Assignments

  • Research Proposals

  • Thesis Support

  • Computer Science Projects

  • Statistical Analysis using SPSS & RStudio

Our diverse skills ensure top-quality solutions. Get in touch for comprehensive support:

Email: [email protected] Discord: domain_ezo Telegram: @zaer_ezo


r/pythonhelp • • May 27 '26

pandas group by function for data analysis

0 Upvotes

https://youtu.be/yQANufD_f3k?si=4MdgrzsaWaqKnyHG

Here's a beginners tutorial for learning group by function for data analysis.


r/pythonhelp • • Aug 08 '25

I need support! Antivirus kills Python.

0 Upvotes

I made a video game in Python, something very simple and indie, but I have a big problem now, which is that I'm creating .exe, but the antivirus says it's a virus (which obviously isn't true), and I've tried everything, but it still says it's a virus. I tried creating an installer, I created an onedir file, or tried compressing it all into a single .exe file, but nothing. Every time I open it, Avast or Windows Defender warns me that it might be a virus. It's a big problem because I wanted to put them on Itch for free, but no one will ever download it if they think it's a virus.


r/pythonhelp • • Jun 24 '25

I am new to python, professor said to install VScode,what is the process to install

0 Upvotes

Help me to install


r/pythonhelp • • Jun 10 '25

Best way to learn python

0 Upvotes

2025 graduate here ..all my friends have joined coaching institutes In hyd I m confused between online coaching or offline 🤧 Pls help me


r/pythonhelp • • Jun 12 '25

Should I drop Mimo for the Harvard Python courses?

0 Upvotes

I’ve been using Mimo for some time now learning how to code in Python and I recently discovered the free courses Harvard offers. I’ve wanted to give them a shot but I’m unsure if I should drop Mimo and if I should finish my Mimo Python course first.


r/pythonhelp • • Nov 27 '25

I need a study group

0 Upvotes

Hi! I've started a Python course from scratch, I need a study group to collaborate with.


r/pythonhelp • • Jun 24 '26

Python Script and Adobe Workfront

Thumbnail reddit.com
0 Upvotes

r/pythonhelp • • Dec 11 '25

Quero criar uma animação de presente de 1 ano de namoro, alguém me dá um rumo

0 Upvotes

Galera, então, eu comecei a mexer com Python por causa de um vídeo no TikTok. Sempre quis fazer aquelas animações, e sei que não é só com Python, o JavaScript também dá pra fazer essas coisas incríveis. O problema é que não achei nenhum tutorial decente no YouTube ensinando, pelo menos não em português 😅.

Basicamente, eu queria uma dica ou um rumo pra isso. Sinceramente, mexo com JavaScript e Python só por diversão, porque acho interessante, então qualquer sugestão de caminho seria ótima. Pode ser Python, JavaScript ou qualquer outra ferramenta que permita criar animações por código.

Ah, e só pra contexto: eu ainda sei o básico do básico, mas estou estudando mais a fundo porque quero fazer uma animação de presente de 1 ano de namoro pra minha namorada. Então se puderem levar isso em conta, já ajudaria muito!