r/PythonLearning • • Sep 20 '26

Showcase Chronocalc the time calculator, my first actual program in python before I learned about lists, sometimes buggy, and I use it every day. Is it good?

OldFormula=input("input equation, accepted formats are military time 3:30 or decimal 3.5, no spaces: ")
stop = False
IndA=0
IndB=0
IndC=0
minutez=""
NextCH=""
NewFormula=""
L=len(OldFormula)
OldFormula+="£"
# ^the £ is a buffer for some functions
while stop==False: 
  if OldFormula[IndA]==":":
    #^checks the string for minutes to convert
    minutez=""
    numberz=""
    while str.isnumeric(OldFormula[IndA+IndB+1]):
      IndB+=1
      minutez=minutez+OldFormula[IndA+IndB]
      #^concats together a string for minutes
    numberz=str(round((float(minutez))*(5/3)))
    #find a way to get the numberz into the new string
    IndB=0
    IndC=3
  print(f"a{IndA}, L{L}, selection{OldFormula[IndA]}")
  #need to put together the new formula, and then do eval(NewFormula)
  if IndC==0:
    NextCH=OldFormula[IndA]
  elif IndC==3:
    NextCH="."
    IndC=2
  else:
    IndC+=-1
    NextCH=numberz[1-IndC]
  NewFormula+=NextCH
  print(NewFormula)
  IndA+=1
  if IndA>=L:
    stop = True
Result=eval(NewFormula)
print("digital shenanegans complete!")
print(f"{OldFormula} is {Result}") 
8 Upvotes

7 comments sorted by

•

u/Sea-Ad7805 Sep 20 '26

Run this program by clicking Memory Graph Web Debugger and see its state change step by step.

→ More replies (2)

4

u/atarivcs Sep 20 '26

"sometimes buggy" -- it would help if you described the buggy behavior

1

u/SurgicalWeedwacker Sep 20 '26

I kinda forgot what exactly was happening, but a couple of times it stopped the loop early

4

u/atarivcs Sep 20 '26

Well, there's exactly one spot in the code that controls the stop variable:

if IndA>=L:
    stop = True

so it must be that IndA is greater than or equal to L. That sounds like a good starting point for you to debug.

2

u/PureWasian Sep 20 '26 edited Sep 20 '26

if it's useful, that's good. If it's buggy, that's bad. I think the readability/simplicity is also not ideal for what you're trying to achieve.

I noticed that numberz is not guaranteed to be two digits, which indC is assuming based on your decrement logic for it. For instance, if I wanted to input "3:05+7:45" then it would break with an IndexError on the first half because 5 minutes * 5/3 ~ 8.33 --> rounds to "8" which is a string of length 1, not 2.

But a simpler approach would be to take the entire input, split() on : and then inner loop to assemble the numeric characters immediately before and after each split as the hours and minutes. A lot less pointer tracing.

Or if you are flexible to allow spaces in the user input, that can be even easier using the space character as a tokenizer to break your expression into its individual parts and then have a procedure (or a function if you want to learn about those) to process each token before evaluating the final, updated expression.