Good day everyone!
I started out with the time calculator project and now I’m stuck
I ran the code yesterday and it worked perfectly on my vscode editor…
I decided to round it up today by including a ‘try and except’ block because there were some errors I needed to handle…
But, after adding the "try, except’ block, suddenly my code doesn’t even run at all; both on vscode and replit …
It doesnt even display an error at least for me to atleast know what to do…
It just does nothing , staring at me…
It’s really annoying, i need help
Here’s the link to my code (https://replit.com/@97598311FC/boilerplate-time-calculator-3#time_calculator.py)
I also found out that when I try to run my code on replit, I see warning at the bottom left corner of my code which shows ‘cpu processing power is close to limit’
Could this be the cause?
if so, can anyone tell me how to fix it pls?
Then remove the block?
I don’t even understand what you try to do there…
The try-except block is there to catch errors. You put something in the “try” block that could fail and have the except block to throw an error if it actually does fail.
Point is “throwing an error” - you are not doing that. You are trying to use it like an if-else kinda thing. However that’s not what’s happening. What is happening is, it’s trapped in the except-block. I’d need to look up what exactly the interpreter does in this case - but basically, if the except doesn’t actually catch the error, it is run infinitly. That’s why there is no error and why you get the warning: the except block keeps running forever.
ohh , is that it?..
let me explain further what I’m trying to do
The code I wrote works for things like
int(4 )+ int(9)
int(45) + int( 2)
because 4 , 9, 45 and 2 can be written as strings which can eventually be converted into integers
But I found out that
throws an error because there’s a zero before the numbers
So, I was trying to handle these errors by using the ‘try-except’ block so that i can convert all those numbers back to normal numbers by removing all the zeros in them using a for loop…
I wanted to get back these
So, can you pls tell me how I can go about it?
Ehm yeah, it does - but 04 will ALWAYS throw an error because Python doesn’t recognize this as anything → throwing a “Syntax error invalid token”. However nobody cares - because you don’t deal with 04 but with "04" which is a string. And int("04") doesn’t throw an error and casts the string to the number 4 no problem.
And because Python doesn’t recognize 04, you cannot do anything with it, not even remove the zero.
In short, there is nothing to do. Remove the try-except block, because you are only getting valid inputs which can be cast to integers.
Remove the try-except block and see if the warning still appears.
Replit doesn’t provide a lot of resources thus it’s no surprise you reach that rather fast. However a CPU limit just means the code will execute slower - but it will still execute.