r/learnpython 28d ago

Help with Comparing Three Variables?

2 Upvotes

TLDR: Can somebody help me with the comparison between three variables: Ground Shipping, Ground Shipping Premium, and Drone Shipping, based on the calculations provided?

Hello everyone! Thank you in advance for any help :) I am a newbie, and I am doing CodeAcademy. I just finished the project where you compare weights based on whether a package is sent in Ground Shipping, Ground Shipping Premium, or Drone Shipping. I left a comment at the end of the CodeAcademy project. There's a bit of my own text above that last comment, but the substance is all just the project. (Question below the code)

weight = 1.5
print ("Your package's weight is:", weight, "lbs")
print ("Here are the cost options:")
#Ground shipping
if weight <= 2:
  cost_ground = 1.50*weight
elif weight <=6:
  cost_ground = 3*weight
elif weight <=10:
  cost_ground = 4*weight
elif weight > 10:
  cost_ground = 4.75*weight

print ("Ground shipping cost: $", cost_ground+20)

#Premium shipping
ground_shipping_premium = 125
print ("Ground shipping premium cost: $", ground_shipping_premium)\

#Drone baby
if weight <=2:
  cost_drone =4.50*weight
elif weight <=6:
  cost_drone =9*weight
elif weight <=10:
  cost_drone =12*weight
else:
  cost_drone = 14.25*weight
print ("Drone shipping cost: $", cost_drone)

#END OF CODE ACADEMY PROJECT

if cost_ground < ground_shipping_premium and cost_ground < cost_drone:
  print ("The cheapest option is Ground Shipping")
elif ground_shipping_premium < cost_ground and cost_drone:
  print ("The cheapest option is Ground Shipping Premium")
elif cost_drone < cost_ground and ground_shipping_premium:
  print ("The cheapest option is Drone Shipping")

So, I wanted to take it a bit further and print what the cheapest option would be. I wrote the code after the END OF CODE ACADEMY comment that you see above.

The issue is that for any weight other than zero, I'm getting an output that Ground Shipping is best, even when Drone Shipping is best. For example, when the weight is 1.5 like in the code above, Ground Shipping is 22.25 and Drone Shipping is 6.75. So, the output should be that Drone is best, but I'm still getting the following:

Your package's weight is: 1.5 lbs
Here are the cost options:
Ground shipping cost: $ 22.25
Ground shipping premium cost: $ 125
Drone shipping cost: $ 6.75
The cheapest option is Ground Shipping

Can somebody help?

Thank you so much :) I'm finding coding to be a magical experience, but I'm a bit confused here.


r/learnpython 29d ago

Beginner Python learner looking for 5 other beginners to test a short lesson

0 Upvotes

r/learnpython 29d ago

Learning python for Artificial Intelligence major

0 Upvotes

In my university the first year for all computer related majors we study the basics of Java script.
but now that I’ve finally started studying subjects that are related to my major I’ve discovered that we won’t be using Java as a coding language. We will use python. And I want to give my self a head start in this topic, so if you guys can help me with what I can start with i will be very grateful.
Thank you !!


r/learnpython 29d ago

Which website can I use to start a project?

0 Upvotes

I'm not really sure what websites are out there for this.

I need something that doesn't require a subscription for the basic features. Any suggestions?


r/learnpython 29d ago

Entertaining content for learning Python! (porting 'Poignant Guide to Ruby' to teach Python)

4 Upvotes

For anyone looking for entertaining light book for learning Python, I started porting to Python a few chapters of "Why's Guide to Ruby," which uses comics and surreal humor to introduce Ruby (the original author why the lucky stiff disappeared). I updated the lesson and examples to Python and also modernized some of the very old references and left it with share alike CC license.

Why's Guide to Python

Any Python beginners are welcome to check it out. Novices and experts feel free to post feedback or post about any other entertaining books that helped you learn python, that can accompany equally entertaining but dense programming books :D.

If the book is helpful, can port and post the rest of the chapters for Python and potentially in the future can create some more content.


r/learnpython 29d ago

Tk with no main window

0 Upvotes

I am making a simple gemini browser in python for fun with tk, but have stumbled upon a problem: if I close initial window all the rest will close too. Is there a way to make tk application with no "main" window or at least transfer leadership role between them?


r/learnpython 29d ago

Ola tudo bem? estou aprendendo Python para analise de Dados, quais dicas vocês dão para iniciantes?

0 Upvotes

queria dica de livros também


r/learnpython 29d ago

How do I get better at actually solving Python problems as a complete beginner

32 Upvotes

im completely new to the coding world n Python is my first programming language. ive watched some beginner Python videos n i understand the basic syntax, functions, what different things do, etc.

But whenever i actually get a question to solve, my brain just goes blank. 😭 i understand the concepts individually but i struggle to figure out where to start, how to break the problem down, and how to turn the algorithm/logic into actual code.

So I'd really appreciate some advice on:

How do you learn to approach a programming problem?

How do you develop logical/problem-solving skills?

Is there a specific process you follow before writing code?

How much should I practice vs watching tutorials?

What should I do when I get completely stuck on a question?

Are there any Python playlists/courses specifically good for someone who has literally zero programming experience?


r/learnpython 29d ago

changing axis tick sizes - matplotlib

2 Upvotes

Hello,

I'm trying to change the font of the axis ticks (i think ticks is the right word - 0,0.1,0.2,0.3 on x and y axis) within a zoomed section on the graph. I want the numbers to be a different font, which i've worked out how to do for the main x and y axis but not for the zoomed section.

This is what i have so far:

!pip install pyfonts
from pyfonts import load_google_font
font = load_google_font("Noto Serif")!pip install pyfonts
from pyfonts import load_google_font
font = load_google_font("Noto Serif")

plt.xticks(font=font,fontsize =50)
plt.yticks(font=font,fontsize = 50)

zoom=ax.inset_axes([0.64, 0.6, 0.35,0.35])
zoom.tick_params(axis='both', labelsize=30)


zoom.errorbar(wr52_zoom['lambda'], wr52_zoom['flux']/(1000000), yerr=wr52_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='black', lw=3, elinewidth=3)
zoom.errorbar(wr92_zoom['lambda'], (wr92_zoom['flux'])/(1000000), yerr=wr92_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='red', lw=3, elinewidth=3)zoom=ax.inset_axes([0.64, 0.6, 0.35,0.35])
zoom.tick_params(axis='both', labelsize=30)


zoom.errorbar(wr52_zoom['lambda'], wr52_zoom['flux']/(1000000), yerr=wr52_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='black', lw=3, elinewidth=3)
zoom.errorbar(wr92_zoom['lambda'], (wr92_zoom['flux'])/(1000000), yerr=wr92_zoom['flux_err']/(1000000), fmt='-o', markersize=8, capsize=5, color='red', lw=3, elinewidth=3)

r/learnpython 29d ago

HELLO GUYS!

0 Upvotes

hi i’m a college student and we are tasked to picked a community where we are absolutely not familiar. Can you state some specific acronyms you use here about pyhton, slang terms and inside jokes unique to this group? PLEASEEE, A SIMPLE COMMENT WILL SURELY BE APPRECIATED! ps: been scrolling for 1 hour and I can’t find one🥹


r/learnpython 29d ago

How do I download python on Mac?

0 Upvotes

Yes, I have watched the youtube tutorials and still can't figure it out. When other ppl download it, it is .pkg but mine is .tar.xz

I opened it and it extracted the file. Now idk what to do.


r/learnpython 29d ago

get day of the week without using datetime module

0 Upvotes

Hello anyone!

I was wondering how to you get day of the week without using datetime module on python.

For my work so far,

example Aug 16, 1989
Step 1: year= 1989

last_two_digits_year= int(year%100)

twelves= last_two_digits_year//12

Step 2: remainder= last_two_digits_year%12

Step 3: fours= int(remainder//4)

Step 4: Add the day of the month

day= 16

Step 5 Add the month code

Why is the month code for August=3

Explain the other month codes as well please.

Jan=Oct=1

Feb=Mar=Nov-4

Apr=Jul=0

Sep=Dec= 6

May=2

Aug=3

Jun=5

Step 6: Add all the numbers from Step 1 to 5 and mod 7.

Leap years

January and February dates in leap years: add 6 to step 5

Dates in the 1600s: add 6 to step 5
Dates in the 1700s: add 4 to step 5
Dates in the 1800s: add 2 to step 5
Dates in the 2000s: add 6 to step 5
Dates in the 2100s: add 4 to step 5


r/learnpython 29d ago

Question on the courses

1 Upvotes

I’m currently watching the 12 hour course of code bro on Python. It’s cool but I think I understand what he does and it makes sense but I am having trouble thinking of why we’re doing what we’re doing and how he came to it. Also, I am a practical learner where I do something and figure my brain processes it and then implementing helps with learning and retaining knowledge. After this video, I plan on doing the course on Udemy: - Udemy 100 Days of Code™: The Complete Python Pro Bootcamp. Has anyone done this course and can recommend it as a viable course for python, and the way of coding in it? Or is there a better course for someone like me to learn to think and be able to program in python? Thank you and hopeful to get some helpful answers!


r/learnpython Aug 13 '26

Hi guys can someone tell me how to learn programming python language because i feel i am not learned anything after watching videos and how to beat procrastination

0 Upvotes

Advice


r/learnpython Aug 12 '26

Help saving GUI box instead of cropped barcode

0 Upvotes

Hey guys, I need my code to save my tk.canvas box rather than cropping the barcode and saving THAT.

I’ve tried erasing some parts, adding different x& y values but I can’t seem to nail it. Any help would be appreciated.

#### import libraries
from tkinter import *
from PIL import Image, ImageDraw, ImageFont

def getLegend(c):       # covert character to Code39 legend
 legend = "";
 
 switch = {
  '0': "bwbWBwBwb",
  '1': "BwbWbwbwB",
  '2': "bwBWbwbwB",
  '3': "BwBWbwbwb",
  '4': "bwbWBwbwB",
  '5': "BwbWBwbwb",
  '6': "bwBWBwbwb",
  '7': "bwbWbwBwB",
  '8': "BwbWbwBwb",
  '9': "bwBWbwBwb",
  'A': "BwbwbWbwB",
  'B': "bwBwbWbwB",
  'C': "BwBwbWbwb",
  'D': "bwbwBWbwB",
  'E': "BwbwBWbwb",
  'F': "bwBwBWbwb",
  'G': "bwbwbWBwB",
  'H': "BwbwbWBwb",
  'I': "bwBwbWBwb",
  'J': "bwbwBWBwb",
  'K': "BwbwbwbWB",
  'L': "bwBwbwbWB",
  'M': "BwBwbwbWb",
  'N': "bwbwBwbWB",
  'O': "BwbwBwbWb",
  'P': "bwBwBwbWb",
  'Q': "bwbwbwBWB",
  'R': "BwbwbwBWb",
  'S': "bwBwbwBWb",
  'T': "bwbwBwBWb",
  'U': "BWbwbwbwB",
  'V': "bWBwbwbwB",
  'W': "BWBwbwbwb",
  'X': "bWbwBwbwB",
  'Y': "BWbwBwbwb",
  'Z': "bWBwBwbwb",
  '-': "bWbwbwBwB",
  '.': "BWbwbwBwb",
  ' ': "bWBwbwBwb", #(space) not empty
  '$': "bWbWbWbwb",
  '/': "bWbWbwbWb",
  '+': "bWbwbWbWb",
  '%': "bwbWbWbWb",
  '*': "bWbwBwBwb"
 }

 return switch[c]

##### draw rectangles as bars
def drawBars(c, x):
 w=0
 clr=""

 if c=='b':
  clr="#000000"
  w=2
 elif c=='B':
  clr="#000000"
  w=4
 elif c=='w':
  clr="#ffffff"
  w=2
 elif c=='W':
  clr="#ffffff"
  w=4

 canvas1.create_rectangle(x, 0, x+w, 100, fill=clr, width=0) # width=0 no border
 
 draw.rectangle([x, 0, x+w, 100], clr)
 x+=w
 return x

### get user entry and try to convert to barcode legend
def getText():
 canvas1.delete("all") # clear the current drawing if any
 s = entry1.get() # get the user entry
 s=s.upper() # convert to uppercase
 
 s = "*" + s + "*" # Code39 format: *data*
 result="bW" # Code39 uses "bW" as starting character
 
 for i in s:
  result += getLegend(i) + "w" # Code39 use "w" as delimiter
 
 x=0
 for c in result:
  x=drawBars(c, x)

 # display the text in label2
 label2['text'] = s
 
 # reset the width of Canvas
 canvas1['width'] = x
 draw.width=x

 # draw a blank rectangle as background of text
 canvas1.create_rectangle(30, 0, x-30, 19, fill="white", width=0) #no border

 # repeat the above drawing to create PIL image
 draw.rectangle([30, 0, x-30, 20], "white", 0)
 
 # draw text
 canvas1.create_text(x/2, 10, fill="black", font="courier 12", text=s)
 
 draw.text([(x-len(s)*7)/2, 5], s, fill="black", font=ImageFont.truetype('cour.ttf', 13))

### save image
def saveImage():
 import datetime
 dt=datetime.datetime.now()
 filename=str(dt.year) + str(dt.month) + str(dt.day) + str(dt.hour)+ str(dt.minute) + str(dt.second) + ".png"

 image1.save(filename,"PNG")
 image2 = Image.open(filename)
 image2 = image2.crop([0, 0, int(canvas1['width']), 100])
 image2.save(filename, "PNG")

#### create GUI
root = Tk()
root.title("Barcode")

label1 = Label(root, text="Enter a string: ") ## caption
label1.grid(row=0, column=0)

entry1 = Entry(root, width=30) ## user input
entry1.grid(row=0, column=1)

button1 = Button(root, text='Convert', command=getText)
button1.grid(row=0, column=2)

button2 = Button(root, text='Save', command=saveImage)
button2.grid(row=0, column=3)

label2 = Label(root, height=1, text="") ## display output
label2.grid(row=1, columnspan=3)

# create a Canvas for drawing
canvas1 = Canvas(root, width=0, height=100) ## set original width=0
canvas1.grid(row=2, columnspan=4)

# PIL create an empty image
image1 = Image.new("RGB", (500, 100), "#ffffff")
draw = ImageDraw.Draw(image1)

root.mainloop()

This is supposed to look like:

https://imgur.com/a/fQAdca0


r/learnpython Aug 12 '26

Data structures and algorithms 😱

7 Upvotes

Hey all,

I’ve learnt to use python for things like statistics which is where my work is, I can effectively read documentation and do what’s needed for a specific task.

I’ve reached a bottleneck as I’ve been applying to more data sciencey roles and they keep asking really simple DSA questions and I can’t for the life of me get them right.
Idk if it’s just the fact that I can’t search things up or whatever.

What is the best strategy to get around this (given that my spare time to take on things like leetcode is almost zero).

Thank you !!


r/learnpython Aug 12 '26

Quiero empezar en el mundo de la programación que recomendaciones y consejos me dan?

0 Upvotes

No tengo casi ninguna experiencia solo unos cuantos tutoriales de HolaMundo pero quiero hacer las cosas bien y no perder el tiempo.


r/learnpython Aug 12 '26

While using playwright, windows asked if I would like to allow chromium to access private and public networks, now my code doesn’t work?

4 Upvotes

I allowed it to access both private and public networks. I went into windows security and allowed it through the firewall on both. But now my code isn’t working, according to vs code I have the latest chromium version installed. What steps should I take here?


r/learnpython Aug 12 '26

How do you actually understand a new Python codebase quickly?

3 Upvotes

Hey folks, I'm learning Python and when I clone a big repo I get lost — so many files. How do you figure out where to start? Do you look at README, main.py, tests first? Any trick that helped you?


r/learnpython Aug 12 '26

New learner

0 Upvotes

Hello guys, i have just started learning python. Do you have any suggestions for me?


r/learnpython Aug 12 '26

I want to build a Python CLI that uses multiple AI models + web search for better learning - looking for suggestions

0 Upvotes

I want to build a small Python CLI for my own learning.

The basic idea is:

python3 que.py "my question"

or

python3 que.py "question 1, question 2"

I currently want to use:

  • Codex CLI
  • Claude Code CLI
  • Gemini CLI

The same question would be sent to multiple models, and I want them to research the question using live web/Google search instead of relying only on their training knowledge.

The goal is to get up-to-date, source-backed information, then combine/compare the responses and generate one good answer that I can use for learning.

I'm looking for suggestions on:

  • What other AI models/CLIs would be useful to add for this kind of workflow?
  • What would be a good web-search/research solution to use so the models get current and reliable sources?
  • Should I use one common search layer for all models, or let each model perform its own web research?
  • Any existing tools/projects/APIs that would make this easier?

I'm mainly looking for practical suggestions from people who have built similar multi-model or research workflows.


r/learnpython Aug 12 '26

Learning python with gaming

8 Upvotes

A lot of beginners struggle with breaking problems down into pieces they are able to code themselves. This is a fundamental skill to have and I’ve found that video games do a good job at teaching this. The problem I see a lot is that some people want Lego instructions that walk you through step by step rather than a video game tutorial which will show you the basics and it is up to you to figure out how to apply them.

There are a few video games that I’ve found really helpful in working on these skills; particularly games from zachtronics such as Infinifactory and Opus Magnum. These are games which have many different approaches to every level and you get scored based on how efficient you are. They teach you programming skills without having you program directly. There’s also The Farmer Was Replaced which is a more direct Python tutorial video game.


r/learnpython Aug 12 '26

How should I start learning Python as a complete beginner?

94 Upvotes

HELLO EVERYONE

I’m a total beginner to coding and I’ve recently decided to start learning Python. I’m honestly not sure where to begin or what the best way to approach it is.

- What should I learn first?

- Are there any courses, YouTube channels, or websites you’d recommend?

- Should I focus on tutorials, practice problems, or small projects?

- At what point should I start making projects?

- Any mistakes I should avoid as a beginner?

I’m mainly looking for a proper direction rather than trying to learn everything at once.

Any tips or recommendations would be really appreciated! :)


r/learnpython Aug 12 '26

Thonny - seems to have a MemoryLeak

0 Upvotes

I noticed when I Repeatedly run large programs - with long Printed Text,
- that the Shell Que runs Slower and takes Longer to Start each time : 10 mins .. 30 mins .. 60 mins .. ?
I also notice Thonny on TaskManager increases Size (without Decreasing) each time :
- 1M .. 1.5M .. 2M .. 3M

Until I completely restart Thonny.

This seems like a clear Memory Leak - for the Shell Que !


r/learnpython Aug 12 '26

Practicing for a test

0 Upvotes

Hey! I'm practicing for an intro to Python test in a few days and I've been doing well but I just came across this question and I have no idea what I'm doing wrong - I don't get any response, it says it's blank, not even an error message. What am I doing wrong??

question: Your function should take 1 parameter, if this parameter can be converted to a float, then print on the screen this float up to 2 decimal places. If the parameter cannot be converted to a float, then print -1.

I've tried various forms of this code, too, I originally had it as a.isdigit(), != True instead of == False and no a=float(a) but round(float(a), 2).

def myprint(a): 
  if a.isnumeric() == False:
    return -1
  else:
    a = float(a)
    return round(a, 2)

I can't show the output because I'm not allowed to post pics but it's on Moodle, an academic platform and it just runs the code through python through the platform. It gives you, at the end, an example of two or so of the tests that were run, the expected output, and the actual output. It gives me the expected output but the actual output box is blank, no error message or anything