Current location: Homepage > kotlin > How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep28

How to use ChatGPT in 2025 _ ChatGPT Tutorial _ ChatGPT Full Course - Ep28

2025-07-11 13:43:57 [html] Source: MetaScripta
and I'm trying to addexception handling for that particularcode and build ai startupthen I'm having a customizedexception handling that is when a userwill give uh like index value likedecimals 0.1 0.2 so on and so forth whatwe do and how to handle that so we'llask these questions to chat gbt let'ssee what is the response now let's seethe next task that is Task number two wepaste this particular code that is zerodivision error and ask for the exceptionit will find the error and provide theexception and then we will ask any otherlogic in order to solve this programright these two tasks will perform withrespect to exception handling using chatGPT let's switch on to the interface nowI can use the new chat so I'm pressingon the new chat here in the left and uhI'm trying to paste a codee which ishaving index value error issue and askan exception to this particular code andget the modified code so I'm just givinga normal code and it says it looks likeyou have provided a simple pythonsnippet that creates a list of acontaining five elements and thenprompts the user to put the input to theindex the code and then access the valueand it will print the index for the sameif you have any questions about the codeyou can ask me so what it is Ping iswhat is the error that can happen in thecode above so I'm asking a question whatmight be the error obviously the codeyou have provided these are the errorsit can happen input type error and indexerror it is giving explanation also inorder to solve this particular uh erroryou can use try except block rightwithout us asking provide exceptionhandling for this above code I'm justasking what is the error it might comeif at all if it wants to how do youhandle it is giving the complete tryexcept Block in this particular modifiedcode right so let's ask our customizedexception handling question what it wasdiscussed if userprovides decimal indexvalue asinput how to handle so I'm just askingmy own question in my normal languagewithout any sentence Framing and it istrying to understand and give me theoutput right so what it is s suggestingus to do we will convert the floatingPoint indexes to the decimal value andthen we will execute the program thefirst conversion is happening then it isproceeding right so this is how it willconvert right if you want to executethis particular program and check how itwill work and if you're having Premierversion of chat GPT then you can copythis paste in the gp4 and try to use TheInterpreter feature in the chat gp4right so for now I'm stopping it herethat we have got the answers exactly howwe wanted and the GPT has UND stood ourproblem statement it is suggested whatall the problems can arise the errorscan arise and how do you solve that withthe help of exception handing programand then again if you give a customizedexception hand to be handled it isproviding the program for that as wellright so let's check out the second taskand let's paste the code which is havingzero index error and just work how itwill take it coming up to the secondtask we are having a program here whichis having the zero division error rightso when you have this error let's seewhat it will do the code you haveprovided will incede cause zero divisionerror because you are trying to divideby zero denominator is zero numerator is10 so this is your program with error ifyou run you will get this output if youget that output how do you solve thatyou can use this particular eelstatement else I can sayplease addexception for above code it triedsolving by using IF Els but I wantexception so let me ask please addexception for above code it will giveyou try and accept block right so anyothermethod to solve the abovestatement or problem let me give it asproblemhere so when you dothis it is telling are giving certainlythere is another way to divide thisparticular 10 numerator with thedenominator zero even though if you geta zero division error how do you solveit so this is what it is it is givingyou the overall picture first we triedhand link asking what is the error justwe didn't ask anything we just pastedthe code it gave us the what error andit also gave the solution for us wedidn't want a defs we wanted exceptionwe asked for exception it provided theexception and any other method if we cansolve this major problem statement ifyou could see it is repeating the samecode what it suggested in if Els righthere if you could see here as a solutionit is repeating the same as another wayit is going to and fro a lot rightthere's no much options it will startgoing to and from right so this is allaboutdebugging your code programs by usingchat GPT the next topic is testing usingchat GPT so the code which you havecreated you want to test your code howdo you do that so we'll be doing thatwith the help of testing and it can betaken up in ch gbt interface so promptnumber one what we will execute we tryto do the unit test for the above codeany code which we have already executedwe'll take that into consideration andwe will try to execute so the problemnumber two suggest code Improvementideas for the above code and Implementany of the idea and provide the coderight so ideas will be given and out ofthat we will ask you can Implement soand so it will give the outputaccordingly so let's check out thisparticular testing how we can carry outin ch GPTinterface here we are in the chart GPTinterface and I'll try to add acode and ask the chartGPT to provide the unit testing so whatit has done is as soon as you add andyou give nothing as an input except thecode you don't ask to perform any otheroperation it will break the particularprogram and try to explain you line byline what is happening right so afterthis we will try toaskperform unittesting on the code above right when youask

(Editor: cs)

Recommended articles
Hot reading