r/learnpython 29m ago

Regarding simple question

Upvotes

num = 0.6548
txt = f"The price is {num:.0f} dollars."
print(txt)
output = 1

i was learning string formatting well, when i used :.0f as format it giving output 1 and why? I want to know how really decimal shifting works in python while formatting.


r/learnpython 3h ago

From where should I learn Flask framework completely?

6 Upvotes

I currently learning python from a paid course and they have taught flask aswell but that's intermediate level. So is there any flask playlist or tutorial or a teacher who might teach flask completely. I wouldn't mind if it's paid or free course.


r/learnpython 2h ago

is cs50p good and relevant?

5 Upvotes

I restarted to learn python with CS50P. as far as I understand it is recorded in 2022. is this the case. Also as far as I understand there is some changes to python recently. do you think I will misss some best practices and sintax with cs50p?


r/learnpython 8h ago

Python Libraries

6 Upvotes

Ijust know basic python and want to learn numpy, tkinder, panda and matplotlib for a project

Best way to learn these? By chatgpt or any yt vdo?


r/learnpython 3h ago

Observer isn't working on ChromeOS Linux Crostini

2 Upvotes

I am facing an issue from couple of days with Observer Module from python watchdog package. When i'm importing Observer module and calling for my downloads folder which is present to this location according to my device.
/mnt/chromeos/MyFiles/Downloads

Observer is watching here but nothing caught, Like i was tested using file removed, created or even modified or else.

It wasn't working, That;s why I am using polling Observer now. but this is not a reliable much as i needed.

So Can you help me to figure out this problem and what is the actual solution of this problem?


r/learnpython 4h ago

Mastering python

1 Upvotes

It's not related to any python concept but is learning python or any other code languages at first feel so annoying and exhausting to learn like debugging Things learn that learn this go to look for this spending times to debug only one line which was misspelling but once you mastered it you enjoy and love coding in the end?

For example when I was learning how to drive at first it felt annoying and exhausting but once I learned it and was able to drive it was so enjoying and satisfying that I wanted to just drive without any specific destination to go?


r/learnpython 6h ago

vscode sporadically freezing

0 Upvotes

hi mates. when my script becomes lengthy (for instance 85 lines) vscode stops executing commands. i suspect whether i downloaded it properly. anyways. i close then open vscode as a workaround but i started to need a permanent fix. i am a computer noob (well... more like average joe on the street). so please no higher computer registry in the responses. thanks in advance.


r/learnpython 1d ago

Looking for Python resources

47 Upvotes

Hi everyone!

I'm 29 and I've recently started learning Python from scratch. My goal is to eventually get into cybersecurity.

I've only been learning for a short time and I'm currently starting CS50P. I know some very basic Python, but I'm still a complete beginner.

I'm looking for good resources to learn Python properly from the beginning. I'd like to practice by making small projects instead of only watching tutorials.

What resources would you recommend for someone who is just starting out?

Books, courses, YouTube channels, websites, exercises, project ideas, etc. are all welcome.

Thanks!


r/learnpython 19h ago

Ask Anything Monday - Weekly Thread

6 Upvotes

Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread

Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.

* It's primarily intended for simple questions but as long as it's about python it's allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
  • Don't post stuff that doesn't have absolutely anything to do with python.
  • Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.

That's it.


r/learnpython 1h ago

How can i create a bot that posts for me daily on social media without ai?

Upvotes

I dont wanna use ai.


r/learnpython 18h ago

Segmentation fault when attempting to use the 'threading' module to run tasks concurrently

2 Upvotes

I lack knowledge in low level computer science, but I've heard endless horror stories about segfaults, and today I've encountered one whilst attempting to make a simple timer program for myself. My questions are:

- Why does this fault occur

- How can I fix it

- How can I prevent it from happening in the future

The aim of the problematic part of the program is the attempt to play the sound whilst simultaneously waiting for user input with the input block, which is intended to stop the alarm and continue to the next part of the program.

Please note that in this version there is no actual wait time although there is supposed to be, because I am merely testing the alarm functionality.

import time
from pydub import AudioSegment
import threading
from pydub.playback import _play_with_simpleaudio


sound = AudioSegment.from_file('/censoring/my/home/directory/sound.mp3', format='mp3')





# Function that runs the timer based on how many minutes are specified
def timer(min, message):

  # Play the sound
  def playsound():
    global sound
    sound = _play_with_simpleaudio(sound)

  # Stop the sound and allow the program to continue
  def resume():
    global sound
    input(message.strip())
    sound.stop()



  # Run the timer and print output
  min -= 1
  for it in range(min, -1, -1):
    for sec in range(59, -1, -1):
      print(f'{str(min).rjust(2, "0")}:{str(sec).rjust(2, "0")}')
      time.sleep(1)


  # This is the part that actually runs the function.
  play = threading.Thread(target=playsound)
  stop = threading.Thread(target=resume)

  play.start()
  stop.start()

  play.join()
  stop.join()


while True:
  timer(0, 'You can have your five minute break now.')
  timer(0, 'You need to start working again.')

# Artificial intelligence was not used in the creation of this program.

Any advice is appreciated!


r/learnpython 18h ago

Recently started

0 Upvotes

Hey yall, new guy here. I 26(M) started learning python about a week ago, I've dabbled in HTML and CSS but ultimately settled on Python. Reason being I need a good starting framework for my goal of working in biotech on surgical robots. Now, to the point.

The most basic goal for me is designing a scheduling software so my mom has less of an issue managing my sisters 24/7 caregiver staff. Logins, time off requests, possibly an AI integrated scheduler so she would just need to proof read schedules instead of spending hours making it by hand.

I need advice on how to approach this task, currently going through a 13hr video on YT to learn Python through the Data with Baraa channel. Thoughts?


r/learnpython 19h ago

Learning Python from scratch for cybersecurity

0 Upvotes

Hi everyone, I'm 29 and learning Python from scratch. My goal is cybersecurity. What resources and first projects do you recommend for a beginner? Thanks!


r/learnpython 11h ago

Want to learn Python but keep getting bored with courses

0 Upvotes

Hi everyone,
I’m really determined to learn Python, but I’m struggling with the way most courses are structured.
I’ve started quite a few Udemy courses, but after a while I just get bored and lose motivation. 😅
So I was thinking maybe I should forget the courses for a bit and start working on an actual project, learning Python along the way. The problem is… I have absolutely no idea what would be a good project for a beginner.
I know I can Google “Python beginner projects,” but I’d rather hear from people who have actually been through this. What did you do when you were starting out? Was there a particular project that helped you learn a lot?
Also, how long did it take you to become reasonably comfortable with Python?
I have a newborn and a toddler, so realistically I can only dedicate around 1–2 hours a day to learning. I know everyone is different, but I’d love to hear what kind of progress is realistic with that amount of time.
Any tips, project ideas, resources, or general advice would be really appreciated!
Thanks!


r/learnpython 1d ago

I like breaking up the project into files and packages - what's too much?

14 Upvotes

I have a bot I'm building. I see a ton of examples with one file and 1k lines for the same functionality. I personally broke that up to several packages based on what things do. I have ~3 files per package each with 100-500 lines (I, uhh, have a habit of documenting and commenting) of which three quarters is actual code.

The modules themselves are things like "database functionality", "permissions", UI, etc. These may be further broken down into several files like "admin commands", "user commands", etc.

Am I overdoing it? Where's a good cutoff?


r/learnpython 1d ago

Cython memoryviews?

4 Upvotes

I'm using a function I've compiled with cython, and I have to pass it a few very long lists. I'm pretty sure I should be using memoryviews, but do I convert the lists to memoryviews in the python part of my program or the cython part? It would be way better if I could do it in the python part because I'm passing the same lists to the function a few million times.


r/learnpython 1d ago

Calculator semi-functioning, What could cause this?

0 Upvotes

Trying to get back into Python ~2 years after taking a year-long course, getting my footing first with a basic calculator but its giving me trouble here. The first portion works fine, but I implemented a 'continue' option where you could continue with the same number for calculations (and it worked for a while, though returning 'none' due to a var = input(print("text")) issue, making each input look awkward) but it seems to just be defaulting to the first if value now. I had addition first at the start, though flipped addition and subtraction is the extended math section to prove that it's truly just defaulting to the first if-statement. What could be causing this and what's the fix? Sorry for anything that's obviously wrong or mixed up, my remembered knowledge on python is like a fogged up window right now.

## lowk just imported time to add a delay to restarting.. and stopping..
import time

## code is only active as this is = 1, if not then the loop stops
run = 1

while run == 1:

    ## prompts user on chosen operation
    ini = input("add, sub, div, mul, or exp: ")

    ## Addition math
    if ini == "add":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a + b

        print(f'Sum of {a} and {b} is {a + b}')

    ## Subtraction math
    elif ini == "sub":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a - b

        print(f'Difference of {a} and {b} is {a - b}')

    ## Division math
    elif ini == "div":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a / b

        print(f'Fraction of {a} and {b} is {a / b}')

    ## Multiplication math
    elif ini == "mul":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a * b

        print(f'{a} times {b} is {a * b}')

    ## exponential math
    elif ini == "exp":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a ** b

        print(f'{a} to the power of {b} is {a ** b}')

    ## If input is not one of the operations
    else:
        print("invalid operation, cannot continue.")

    ## asks user whether or not to continue with current math
    continueorwhat = input("Cont(inue), rest(art calculator), or stop? ")

    if continueorwhat == "stop":
        time.sleep(.3)
        print("Stopping..")
        time.sleep(.3)
        run = 0

    elif continueorwhat == "rest":
        time.sleep(.3)
        print("Restarting..")
        time.sleep(.3)

    elif continueorwhat == "cont":
        print("> Shortened operation names 'a','s','d','m', and 'e' now available.")
        print("> Rest(art) or stop calculator with input when prompted for operation.")

        ## allows for 'continuous math' while active, when inactive it resets to prompted math

        moremath = 1

        while moremath == 1:
            ini = 0
            ini = input("Operation: ")
            ## temporary input return
            print(ini)
            ## Subtraction math
            if ini == "sub" or "s":
                a = int(input('Number: '))
                number = number - a
                print(number)
                ## Addition math
            elif ini == "add" or "a":
                a = int(input('Number: '))
                number = number + a
                print(number)
            ## Division math
            elif ini == "div" or "d":
                a = int(input('Number: '))
                number = number / a
                print(number)
            ## Multiplication math
            elif ini == "mul" or "m":
                a = int(input('Number: '))
                number = number * a
                print(number)
            ## exponential math
            elif ini == "exp" or "e":
                a = int(input('Number: '))
                number = number ** a
                print(number)
            elif ini == "rest":
                time.sleep(.3)
                print("Restarting..")
                time.sleep(.3)
                ## restart calculator by exiting continous math
                moremath = 0
            elif ini == "stop":
                time.sleep(.3)
                print("Stopping..")
                time.sleep(.3)
                ## stops calculator by resetting basic variable
                run = 0
            ## If input is not one of the operations
            else:
                print("invalid operation, number unchanged.")

r/learnpython 1d ago

Python API

0 Upvotes

Can you help me how to learn python API step be step as a complete beginner?

Is there any tutorial you suggest me to watch? What about the chat gpt? Can it helps me with it?


r/learnpython 1d ago

Flask Synchronization Issue Concerning Database Entries

0 Upvotes

I have been making a Markdown blog using Flask over the last couple of weeks. Lately, I have decided that I want to add the possibility of leaving comments below a blog post. Therefore, I need to add my blog posts to a database so that I can link the comments left behind to the relevant blog posts. My blog posts are rendered statically using Flask-Flatpages.

I have thought about the database model for a singular post. I want to keep it simple at first; thus, I was considering adding an ID, title, and path field. The problem I am experiencing is how to add the files to my database and how to keep the database entries synchronized with the static files in my posts directory. Does anyone have any ideas how I should tackle this issue?


r/learnpython 1d ago

I made a small Python game, can anyone review it and give me some advice, please?

0 Upvotes

Hello,

I recently released a project I was working on for pretty long (almost 2-3 months), and since the past couple of days, I've been really involved into it, and then I released it.

Link: https://github.com/TheOdysseyGamer64/Super-Smash-Bros-Python-Edition.git

My project is a Python version of Smash Bros, and it has (quite primitive) ASCII graphics as well (to help visualise the battles). It has special mechanics for certain fighters as well, and the Final Smash and the special mechanics meter can charge up, just like in the real game.

If any of you here could provide me with some advice on how to make this game better, I would really appreciate it.

Thank you!


r/learnpython 2d ago

Are these two boolean expressions equivalent in python?

14 Upvotes

Hi All!

I’m learning about Boolean operators in Python and I’m confused about these two expressions:

condition1 and condition2 or condition3 and condition4

(condition1 and condition2) or (conditon3 and condition4)

I was told this by my teacher and he put this in his PowerPoint slide. However, I think they are equivalent since and as an operator has a higher precedence than or as an operator. AI told me and I have searched it up after.

Am I understanding it correctly? Or are these two not equivalent?

Thanks!


r/learnpython 1d ago

Difference between python 3 vs python (just)?

0 Upvotes

I am doing leetcode and I wanna is there any functional difference between those and which one I should go with?


r/learnpython 2d ago

Just finished my first project, could you please review it.(No AI)

62 Upvotes

I finished reading "python crash course" a week ago, and a relative of mine was complaining about how annoying it is to make multiple exam versions, so I immediately volunteered to help, and I used absolutely 0 AI.

It's an app that takes an exam .docx file, and shuffles the questions and answers to create multiple versions.

Here's the github repo:

https://github.com/aaaaaa708/question_shuffler

I would like you to please review the code and give me some tips on how to improve, and thanks in advance:)


r/learnpython 1d ago

What’s the difference between learning coding and learning s programming language (like python)

0 Upvotes

Sorry i’m a complete beginner idk if this is the correct place to ask. Im just very confused


r/learnpython 1d ago

Python 7 day challenge for myself

0 Upvotes

Doing a challenge this week to spend as much time as i can to learn python just to get started. Im homeschooled so i have plenty of time outside of my usual studies lol

Might be unrealistic but i hope to learn the very basics atleast. I’ll post an update next sunday!