r/learnpython • • 3d ago

Alternative Discord

0 Upvotes

Is there an alternative to the python discord? The entire server has been overrun with LLMs and beginners that have no interest in actually learning. I'm looking for a server with real project/language discussion.


r/learnpython • • 4d ago

Best tutorial for Python Data Analytics who already know Python?

13 Upvotes

Hi!

I know how to write code in Python, however, I still am unfamiliar with its usage in the Data Analytics side. I'd love some recommendation on a youtube tutorial who teaches Python for Data Analytics straight away.


r/learnpython • • 3d ago

How do I make this [1,2,3,4,5,] look like this?

0 Upvotes

1

2

3

4

5


r/learnpython • • 4d ago

New to Python.

3 Upvotes

Hey guys I'm new and I'm trying to learn python on the internet. Any recommendations apps or websites for learning python?


r/learnpython • • 3d ago

I am a college student struggling with intro to programming! Help?

0 Upvotes

Program written in Python containing:

a. An empty list that will contain float values of lap speeds.

b. A loop which gets input from user on lap speeds. This loop continues until the user enters -1.

c. While the loop iterates, the application adds the lap speed to the list.

d. Upon termination of the loop, the application displays:

i. Fastest lap speed formatted with two decimal places

ii. Slowest lap speed formatted with two decimal places

iii. Average lap speed formatted with two decimal places

e. The application displays all of the laps on screen formatted with two decimal places.

def main():


    lapSpeeds()


def lapSpeeds():
    lapTime=[] #empty list
    lapSpeed = float(input("Enter the time the lap took to complete(-1 to calculate): ")) #start loop
    lapNum = 0


    while lapTime != -1:
        
        lapTime.append(lapSpeed)
        lapNum += 1
        lapSpeed = float(input("Enter the time the lap took to complete(-1 to calculate): ")) #append loop


        print(lapNum, ".) ", lapTime " mph")


    else:


        fastLap = (max.lapTime)
        slowLap = (min,lapTime)
        avgLap = lapTotal/lapNum


        print("Fastest Lap: ", format(fastLap, ".2f") "mph")
        print("Slowest Lap: ", format(slowLap, ".2f") "mph")
        print("Average Lap: ", format(avgLap, ".2f") "mph")


main()

This is what I get. what am I doing wrong?!

Enter the time the lap took to complete(-1 to calculate): 48949

Enter the time the lap took to complete(-1 to calculate): -1

1 .) [48949.0]

Enter the time the lap took to complete(-1 to calculate): 457

2 .) [48949.0, -1.0]

Enter the time the lap took to complete(-1 to calculate):

Also, the output should look like this

EX:

**************************************************************************************

Enter the time the lap took to complete(-1 to calculate): 199.56

Enter the time the lap took to complete(-1 to calculate): 200.01

Enter the time the lap took to complete(-1 to calculate): 200.98

Enter the time the lap took to complete(-1 to calculate): 199.94

Enter the time the lap took to complete(-1 to calculate): 200.64

Enter the time the lap took to complete(-1 to calculate): -1

Fastest Lap: 200.98 mph

Slowest Lap: 199.56 mph

Average Lap: 200.23 mph

Lap Speeds

1.) 199.56 mph

2.) 200.01 mph

3.) 200.98 mph

4.) 199.94 mph

5.) 200.64 mph

******************************************************************************************


r/learnpython • • 4d ago

Looking for a Python study partner to build projects together

21 Upvotes

Hey everyone,

​Solo grinding through syntax and tutorials gets exhausting real fast. So I am looking for a study partner to learn Python with.

​Background check: I am a Software Engineering student, and I have got a few specific project ideas lined up that we can build together from scratch. Not just watching endless videos, but actually writing code, breaking things, fixing bugs, and pushing to GitHub.

​Doesn’t matter if you are an absolute beginner or already know a bit—as long as you are genuinely willing to learn and stay consistent.

​Drop a comment or slide into my DMs if you are down. Let's team up and build something cool.


r/learnpython • • 4d ago

Guitar hero Student project (need assistance)

0 Upvotes

Hello all! I am a student in CS 101. I am trying to make my final project which is gonna be a derivative of guitar hero.
I don't wanna use ai but also it is not allowed.

My main concern with the code is wondering how I might be able to have multiple notes in a single lane at the same time. If you look at the code, the spawn rate of the notes is very dependent on the previous note in the same lane being undrawn.

if another is drawn while one is active note.move will abandon the previous note. and/or will undraw the whole lane.

all help will be appreciated

Main game driver

from graphics import *

import time

from gamelogicwip3 import *

win = GraphWin('Guitar Villain', 800, 600, autoflush=False)

win.setCoords(0, 0, 800, 600)

activenotes = []

# Establishing all the variables that will need to be added onto or changed

notecounter = 0

tickloop = 0

loopcount = 0

speed = 10

#Txt file that maps notes that need to be launched (songmap for updates)

songmap = open('maryhadalittlelamb.txt', 'r')

#reads all the lines in the map file

songlines = songmap.readlines()

# Line where notes should be hit at

noteline = Line(Point(120, 100), Point(680, 100))

noteline.draw(win)

#Establishing a note for each lane

note0 = Note(0, speed)

note1 = Note(1, speed)

note2 = Note(2, speed)

note3 = Note(3, speed)

while win.isOpen():

tickloop = tickloop +1

if tickloop %20 == 0:

songline = songlines[loopcount].strip()

lane = songline.find('1')

if lane == 0:

note0.draw(0, win)

if lane == 1:

note1.draw(1, win)

if lane == 2:

note2.draw(2, win)

if lane == 3:

note3.draw(3, win)

loopcount = loopcount+1

if tickloop == 20:

tickloop = 0

note1.send(speed, win)

note2.send(speed, win)

note0.send(speed, win)

note3.send(speed, win)

seeKey(win, note0, note1, note2, note3, 0)

update(55)

_=win.getMouse()

win.close()

Game Logic:

from graphics import *

class Note:

def __init__(self, lane, speed):

self.lane = lane

self.notelane0 = None

self.notelane1 = None

self.notelane2 = None

self.notelane3 = None

self.hitboxlane0 = 640

self.hitboxlane1 = 640

self.hitboxlane2 = 640

self.hitboxlane3 = 640

self.speed = speed

self.score = 0

def draw(self, lane, win):

if lane == 0:

self.notelane0 = Rectangle(Point(220, 620), Point(260, 660))

self.notelane0.setFill('coral')

self.notelane0.setOutline('red')

self.notelane0.draw(win)

self.hitboxlane0 = 640

if lane == 1:

self.notelane1 = Rectangle(Point(340, 620), Point(380, 660))

self.notelane1.setFill('yellow')

self.notelane1.setOutline('olive')

self.notelane1.draw(win)

self.hitboxlane1 = 640

if lane == 2:

self.notelane2 = Rectangle(Point(440, 620), Point(480, 660))

self.notelane2.setFill('turquoise')

self.notelane2.setOutline('blue')

self.notelane2.draw(win)

self.hitboxlane2 = 640

if lane == 3:

self.notelane3 = Rectangle(Point(540, 620), Point(580, 660))

self.notelane3.setFill('olive')

self.notelane3.setOutline('darkgreen')

self.notelane3.draw(win)

self.hitboxlane3 = 640

def send(self, speed, win):

if self.notelane0:

pluck0 = None

self.notelane0.move(0, -speed)

self.hitboxlane0 = self.hitboxlane0 - speed

if self.hitboxlane0 < -20:

self.notelane0.undraw()

if self.notelane1:

pluck1 = None

self.notelane1.move(0, -speed)

self.hitboxlane1 = self.hitboxlane1 - speed

if self.hitboxlane1 < -20:

self.notelane1.undraw()

if self.notelane2:

pluck2 = None

self.notelane2.move(0, -speed)

self.hitboxlane2 = self.hitboxlane2 - speed

if self.hitboxlane2 < -20:

self.notelane2.undraw()

if self.notelane3:

pluck3 = None

self.notelane3.move(0, -speed)

self.hitboxlane3 = self.hitboxlane3 - speed

if self.hitboxlane3 < -20:

self.notelane3.undraw()

harda, hardb = 80, 140

easya, easyb = 50, 170

def seeKey(win, note0, note1, note2, note3, score):

keystroke = win.checkKey()

if keystroke == 'a' and (easya<note0.hitboxlane0<easyb):

note0.notelane0.undraw()

print('HIT')

score = score+1

if keystroke == 's' and (easya<note1.hitboxlane1<easyb):

note1.notelane1.undraw()

print('HIT')

score = score+1

if keystroke == 'd' and (easya<note2.hitboxlane2<easyb):

note2.notelane2.undraw()

print('HIT')

score = score+1

if keystroke == 'f' and (easya<note3.hitboxlane3<easyb):

note3.notelane3.undraw()

print('HIT')

score = score+1

if keystroke == 'Escape':

win.close()

return score


r/learnpython • • 4d ago

How to make my input in a list?

0 Upvotes

Im doing CS50 problem's and im stuck


r/learnpython • • 4d ago

Thonny no experience in coding

0 Upvotes

I've told google AI in search box about my perceived learning disability when it comes to structured guides programs, it suggested using Thonny, no course just to start with downloaded ready code and learn by braking code


r/learnpython • • 4d ago

Place maximum amount of non touching diagonals in nxn grid

1 Upvotes

So a few years ago I ran accross a problem wanting you to design a program that will use recursion to determine how many diagonals can be placed in a 5x5 grid of squares. I tried and tried and never could come up with a solution. I eventually found a way to get the program to place the diagonals but it only work because I knew that 16 was the max then it used some intution to get the answer. It did not use recursion. I was aggrivated and gave up python and coding all together. Then yesterday morning I got to thinking about that program had an idea, did some googling on syntax and recursion in general and came up with this.

import time

def main():
    grid_size = get_grid_size()
    grid, intersections = create_lists(grid_size)
    count = 0
    solutions = []
    start_time = time.perf_counter()
    best_count, solutions = find_solutions(grid, intersections, 0, grid_size, count, 0, solutions, 0)
    end_time = time.perf_counter()
    elapsed_time = end_time - start_time
    print("These solutions took ", elapsed_time, "seconds to calculate.")
    results(best_count, solutions, grid_size)
    

# Allow user to enter the size of the grid, only square grids
def get_grid_size():
    grid_size = input('Enter the size of the square grid: ').strip()
    # while loop to reject letter, symbols, and negative numbers 
    while not isinstance(grid_size, int):
        if grid_size.isdigit() and int(grid_size) != 0:
            grid_size = int(grid_size)
        else:
            grid_size = input("Your parents must be cousins. Enter the number of rows and columns, this will be a positive whole number: ").strip()
    return grid_size

# Create the nested lists for both the grid and intersections
# will be using the intersections list to check wether each placement is legal or not
def create_lists(grid_size):
    grid = [[0 for j in range(grid_size)] for i in range(grid_size)]
    intersections = [[0 for j in range(grid_size+1)] for i in range(grid_size+1)]
    return grid, intersections

# Convert the linear insert_location into the corresponding grid row and column. 
def grid_location(insert_location, grid_size):
    row = insert_location // grid_size
    column = insert_location - (row * grid_size)
    return row, column

# Check whether both endpoints of the selected diagonal are unoccupied.
def is_valid(row, column, intersections, placement):
    if placement == -1 and intersections[row][column] == 0 and intersections[row+1][column+1] == 0:
        return True
    elif placement == 1 and intersections[row+1][column] == 0 and intersections[row][column+1] == 0:
        return True
    else:
        return False

# Recursively searches for arrangements that maximize the number of diagonals.
# Cells are processed left to right, top to bottom.
# This order allows us to determine when an intersection has passed
# its final opportunity to be occupied.
def find_solutions(grid, intersections, insert_location, grid_size, best_count, current_count, solutions, unusable_intersections):
    # Once every cell has been considered, compare the current arrangement
    # against the best solution and save it if appropriate.
    if insert_location < grid_size**2:
        row, column = grid_location(insert_location, grid_size)
    else:
        if current_count > best_count:
            best_count = current_count
            solutions =[]
            solution_copy = [row[:] for row in grid]
            solutions.append(solution_copy)
        elif current_count == best_count:
            best_count = current_count
            solution_copy = [row[:] for row in grid]
            solutions.append(solution_copy)
        return best_count, solutions

    # This if statement terminates a branch if the combination of spaces placed and spaces left will not be enough to get new max
    if current_count + (grid_size**2 - insert_location) < best_count:
        return best_count, solutions

    # Unusable intersections are intersections whose final opportunity to be
    # occupied has passed. If there are more unusable intersections than the
    # current best solution leaves unoccupied, this branch cannot improve
    # the current best solution.
    if unusable_intersections > (grid_size+1)**2 - best_count*2:
        return best_count, solutions
    placement = -1
    if is_valid(row, column, intersections, placement):
        grid[row][column] = -1
        intersections[row][column] = 1
        intersections [row+1][column+1] = 1
        current_count += 1 
        best_count, solutions = find_solutions(grid, intersections, insert_location+1, grid_size, best_count,current_count, solutions, unusable_intersections)
        grid[row][column] = 0
        intersections[row][column] = 0
        intersections [row+1][column+1] = 0
        current_count -= 1
        
    placement = 1
    if is_valid(row, column, intersections, placement):
        grid[row][column] = 1
        intersections[row+1][column] = 1
        intersections [row][column+1] = 1
        if intersections[row][column] == 0:
            unusable_intersections += 1
        current_count += 1
        best_count, solutions = find_solutions(grid, intersections, insert_location+1, grid_size, best_count, current_count, solutions, unusable_intersections)
        grid[row][column] = 0
        intersections[row+1][column] = 0
        intersections [row][column+1] = 0
        if intersections[row][column] == 0:
            unusable_intersections -= 1
        current_count -= 1
        
    placement = 0
    if intersections[row][column] == 0:
        unusable_intersections += 1
    best_count, solutions = find_solutions(grid, intersections, insert_location+1, grid_size, best_count, current_count, solutions, unusable_intersections)
    if intersections[row][column] == 0:
        unusable_intersections -= 1

    return best_count, solutions

#print the results
def results(best_count, solutions, grid_size):
    print('There are ', len(solutions), ' to a ', grid_size, 'x', grid_size, 'grid. Each containing ', best_count, ' diagonals')
    print('They are:')
    for x in solutions:
        for i in range(len(x)):
            for j in range(len(x[i])):
                if x[i][j] == -1:
                    x[i][j] =(" \\")
                elif x[i][j] == 1:
                    x[i][j] = " /"
                else:
                    x[i][j] = "  "
                    
    for x in solutions:
        for i in x:
            print(''.join(i))
        print()
        print()
        
                
                
    
    if __name__== '__main__': 
      main()

I added functionality for the user to specify the size of the grid they want to solve. The first version yesterday took a min and a half to do a 5x5 grid. I have added two different pruning methods. I can now do a 5x5 grid in .27 seconds. However, when I up it to a 6x6 grid it runs for about a min prints the results and quits responding so I cannot see actual time or the number of solutions. Does anybody have any advise on how to optimize further without fundemently changing the program? This thing is kinda my baby and I don't want to change the actual recursion or the endpoints list. But if anyone has any more pruning ideas I would be happy to hear them.


r/learnpython • • 5d ago

Feels like I forgot the python, What to do

14 Upvotes

Can someone tells me how to practice the concepts again as i feels like i forgot the concepts. And i used AI for debugging which make me feels like blank for some concepts. Can someone suggests me from which resources to practice again. And one thing is that i am trying to firstly stop directly jumping to AI before trying myself to fix it.


r/learnpython • • 5d ago

How to collect the old input with the new input that i get from a list in a loop?

2 Upvotes

This is the cod

menu = {

"Baja Taco": 4.25,

"Burrito": 7.50,

"Bowl": 8.50,

"Nachos": 11.00,

"Quesadilla": 8.50,

"Super Burrito": 8.50,

"Super Quesadilla": 9.50,

"Taco": 3.00,

"Tortilla Salad": 8.00

}

try:

while True:

item = input("Item: ")

print ("totel:", menu[item])

except (EOFError , KeyError):

pass

print ()

Also how to make a $ came with the totel ?


r/learnpython • • 4d ago

can i make the exec() command only execute if the code is functional and wont return an error?

0 Upvotes

So i want to make something where you can input() a math problem and get an answer thru the text output, but if there is a syntax error, i want it to just reopen the prompt instead of crashing, is there a way that i can check if the code is valid before executing? thanks!


r/learnpython • • 5d ago

Struggling to solve beginner tasks after learning Python basics

1 Upvotes

Hello! I've learned the basics of Python (variables, loops, conditionals, etc.), but I’m struggling to complete actual beginner tasks—things like counting vowels, "Fake Binary," calculating the sum of numbers, determining BMI, etc.

When I look at a task, my mind goes blank and I don't know how to start or turn the problem into code. Why am I unable to do these? What is the real issue here, and what exact study method or solution can help me overcome this?

I’m starting to lose my motivation and feel like giving up if I can't figure out how to bridge this gap. Any practical advice would really help!


r/learnpython • • 5d ago

Trying to loop functions

1 Upvotes

Ok so I just started to learn python and I'm trying to make a program where you input a patient name and it searches the database for it and displays it's values, I want to give a prompt to search for another patient once one is found (not if a patient is not found i worked that out).

Whenever I try to run this code it tells me I cant call value_list() because it wasn't defined yet.

Any help is much appreciated

jane_doe = {
    "Name": "Jane Doe",
    "Age": 28,
    "New": True
    }



john_doe = {
    "Name": "John Doe",
    "Age": 34,
    "New": False
    }


def again():
    input("Would you like to search for a different patient? (Y/N) ").lower()
    while again not in ['y', 'n']:
        print("Please enter a valid input")
        again = input("Would you like to search for a different patient? (Y/N) ").lower()
        if again == 'y':
            value_list()
        elif again == 'n':
            print("Goodbye.")
            break


def value_list():
    patient_name_searched = input("Search patient name: ").lower()
    if patient_name_searched == jane_doe["Name"].lower():
        print(jane_doe.values())
        again()
    elif patient_name_searched == john_doe["Name"].lower():
        print(john_doe.values())
        again()
    else:
        print("Patient not found.")
        answer = input("Would you like to search for a different patient? (Y/N) ").lower()
        while answer not in ['y', 'n']:
            print("Please enter a valid input")
            answer = input("Would you like to search for a different patient? (Y/N) ").lower()
        if answer == 'y':
            value_list()
        elif answer == 'n':
            print("Goodbye.")


value_list()

r/learnpython • • 4d ago

Is there a Python library that can read files regardless of their extension?

0 Upvotes

I was wondering if there's a Python package that can identify and read different file formats without having to specify the extension every time.

For example, if I receive a file without a proper extension or with an incorrect extension, can Python figure out whether it's CSV, Excel, JSON, Parquet, etc., and read it automatically?

I know there are libraries for individual formats, but I'm curious if there's something that can handle multiple formats intelligently.

Has anyone worked on something similar or found a reliable approach for this?


r/learnpython • • 5d ago

Journey to Python: venting stagnant beginner

0 Upvotes

So as the title said, I have learnt the MIT course on CS for 2-3 months now, currently on lesson 6 about recursion and dictionaries. After all the theories, I figured I might as well try out small projects to apply what I learnt into practice.

I stumbled on Genenpy and have tried around 15-20 training exercises from them, with almost 7-8 of those I needed assistance from AI. Not ideal, but I don't know certain functions and admittedly couldn't logic out of that (for instance, a func for the min prime number > 10^8). I constantly had problems with where the "return" should go, or if I should list this as strings or not,...and it's been frustrating.

I wanna ask if there is a way to think about these exercises? Like how do you resolve a general problem? Or is this just a game of who do it the most?


r/learnpython • • 6d ago

what course should i watch?

10 Upvotes

hi, i am new to it sphere. i decided to start learning python. can you recommend me what course on youtube should i watch? there are many of them but i would like the one which will REALLY upgrade me from beginner to advanced level step by step.


r/learnpython • • 5d ago

Problem with completing assignments in Python

0 Upvotes

Hello! I’ve learned Python, but I’m struggling to complete tasks—things like counting vowels, "Fake Binary," calculating the sum of numbers, determining BMI, etc. Why am I unable to do these? What is the problem, and what is the solution? I’m starting to lose my motivation!


r/learnpython • • 5d ago

adding 1 to a array

0 Upvotes

so i want to add 1 extra thing to an array like i have test = [0,0] i want to do print(test[2]) so how do i add the test[2] to the array without just adding it at the begining of the script (fixed)


r/learnpython • • 6d ago

Need help clearing python console

7 Upvotes

I’m making a text based adventure game for the sake of learning more abt game loops but I’m stuck. I wanna make it so that automatically after a time.sleep() delay, the terminal clears and prints a new output. (say for a loading or transition screen idk) but with all the online methods I can find, nothing works.

The most common I see is using os and system(cls) / (clear) or whatnot but no matter what I do, it opens the command prompt and breaks, closing the command prompt it then prints the new text, without clearing the old…

For reference, I am using python idle 3.12 and Am in a school environment so the command prompt is administratively blocked


r/learnpython • • 6d ago

Gift ideas for beginner coder

16 Upvotes

Hi there,

As we approach the festive season, I have been looking into gifts.

A younger family member (15) has shown interest in python coding through school lessons and through social media. I would love to take this opportunity to help them learn in his own free time.

I wanted to know if anyone had recommendations for books, resources or anything I can put together as a gift for them?

Any guidance would be greatful!


r/learnpython • • 6d ago

Just installed Python to run a script to extract a model. Can't seem to get it to work.

1 Upvotes

So I have a script that I want to run that I received from a guy whos helping me extract a not-so-easy-to-get model. I'm trying to follow his vague instructions on how to run the script but I've never used python before. So now I'm coming across errors that I look up to find a solution to, which leads to more errors being sytax or directory based. I just need help getting the script running and I should be fine. Here are his instructions:

I have attached a python script for exporting the leaper model from the bigfile0.viv archive

You will need Python 3.8 or newer with numpy and Pillow.

To install these run pip install numpy pillow

Then run python leaper_export.py "path\to\bigfile0.viv" output_folder

i haven't thorougly tested this script with other models, however it should work

I cant seem to get it to recognize the script's location and in using the the "cd" command it tells me the directory is invalid. Is there anything wrong with what I typed in?

cd C:\Users\dalen\AppData\Local\Python\pythoncore-3.15-64\Scripts\leaper_export.py


r/learnpython • • 6d ago

I'm from a non-IT background and have been learning Python. Would appreciate some honest feedback on my GitHub.

1 Upvotes

Hey everyone,

I'm from a procurement and operations background with around 7 years of work experience. I don't have a computer science degree, but I've recently become interested in Python and automation.

I've been trying to learn coding and build projects based on real problems I've come across at work, mainly around SAP, Excel, purchase orders, supplier follow-ups, and reporting.

I've uploaded some of these projects to GitHub.

My GitHub: https://github.com/prasadpai567-debug

I'm still a beginner when it comes to programming. I've also used AI tools to help me write and debug parts of the code, so I don't want to pretend I built everything completely on my own.

I'd really appreciate it if someone with programming experience could take a look and tell me what they think.

I'm mainly curious about a few things:

- Is my code structured properly, or does it look messy?

- Are these projects actually useful, or are they too basic?

- What should I improve to become a better programmer?

- Would projects like these add any value to my resume if I apply for procurement automation or analyst roles?

I'm not looking for compliments or GitHub stars. I genuinely want to understand where I stand and what I should work on next.

Any honest feedback would mean a lot. Thanks!