Ok i was getting some Unit Testing done in python. But im tripping now

  Kiến thức lập trình

the problem was :

Convert: Takes a string input in the form “X/Y” where X and Y are integers, computes the percentage X/Y * 100 rounded to the nearest integer, and handles errors such as division by zero or non-integer inputs.
Gauge: Takes an integer percentage and returns:
“E” if the percentage is 1 or less.
“F” if the percentage is 99 or more.
Otherwise, it should return the percentage followed by “%”.
And write a test file using pytest for the above thingy too.

ok yes i get it, i know im a monster for calling the main() back inside the convert function. But it was 4 AM and thats all i could think of.

my main file code

heres the test case code:

ok my test code is correct. but whenever i ran it, the test case where we check the errors raised was giving errors. with “pytest.raises(ValueError): convert(“dog/cat”)”

but i do know that my main code is whats nessed up.

Ok now, i prompted the “you know who” to try and get some hints on the answer.
and welp, it seems try catch needed to be executed twice. Can someone enlighten me for a better way ? This is making my blood pressure rise.

heres the correct main file code for reference :

I know that the part of the problem is the problem itself.
LIKE BRUH JUST USE THE FUNCTIONS FOR THE STUFF THAT U NAMED IT AFTER.
IF THE FUNCTION IS HANDLING CONVERSION WHY DO U NEED TO PROMPT THE ERROR HANDLING INSIDE IT TOO.
But this is just my inner voice which is bruised because i couldnt solve it till 3 in the morning.
help me out bros/sis give me a better cleaner code idea.

New contributor

Hardik Katyal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT