Fix Our Decimal Calculator Problem - Python Kivy GUI Tutorial #18

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys john elder here from coding.com and in this video we're going to fix the decimal problem with our calculator for kiwi and python all right guys like i said in this video we're going to look at the decimal problem but before we get started if you like this video you want to see more like it be sure to smash the like button below subscribe to that channel give me a thumbs up for the youtube algorithm and check out konami.com where i have dozens of courses with hundreds of videos that teach you to code use coupon code youtube1 to get 30 off membership it's all my courses videos and books for one time fee at just 49 which is insanely cheap okay in the last video we worked on some of these secondary buttons and very quickly i coded a little the dot thing here and sort of on the fly added something to where we don't get more than one decimal point at a time so we can't put like 3.0.6.7 right it's just 3.0 but in doing that we sort of introduced a bug that i didn't notice at the time and somebody mentioned afterwards in the comment section that if we have another number for instance two here and we want to add a point a decimal point to it we can't right so very quickly we're going to knock this out it shouldn't take very long so it's going to be a short video we are taking aspen to the vet actually today to get spayed so some of you guys know aspen from past videos so uh be thinking about aspen today uh so so let's head over here and i've got our calc.kv file on our calc.pi file from the last video if you didn't see the last video check the link in the comment section below and so let's just come down here to the dot section and here's where we're we did the code yesterday so what we did was we said hey if there's a dot already in our text box don't do anything right otherwise add a dot towards the end well right here you probably notice if we do this and there's already a dot in the first number so 3.0 plus 2.0 we can't add the 2.0 because this thing right here is not allowing us to do that so how do we fix that well we've got our prior thing already here and let's go ahead and break this up so if we've got 3.0 plus 2.0 those are two sets of numbers and they're separated by the plus so let's break this up like we did way back in our math section where we split everything into a python list so let's do that again let's come up here and let's just paste this in and let's say split our text box by plus now we've only got plus right now so this is all we have to do once we work with the other math signs minus multiplication division we'll have to modify this more but for now this will work because we only have plus so we're going to split all of our things into that so now let's create a new if statement let's go if and let's test to see if plus is already in prior right if it is what do we want to do well we want to just do all the stuff we did down here i'm just going to copy this come up here let's paste this in what we want to do is add the period to whatever's to the end of this thing and then output it back to the screen then we can go change this to an l if so otherwise if that already exists so basically if there isn't a plus sign already then we'll test to say well does it have a dot already if so don't do anything if it doesn't have a dot and it doesn't have a plus sign then we can just put a dot at the end so let's go ahead and save this and run it see if that worked no that's not going to fix our problem but it's the first step so let's go 3.0 uh point three that doesn't add a point so that worked we can now go plus 2.0 now that works problem is here now we can also still because this add more dots which is a problem so now we need to fix that which brings us to this guy right here so we can split apart all of these things and we can say hey does the last item in this list already contain a dot if it does don't do anything if it doesn't okay you can add one right so we can get the last item by calling num list and then just negative one the negative one if item of our list is the last item so what we can do is we could say hey if there's a plus sign already which means we've already got a couple of sets of numbers right and if there's a plus sign in there and if it if there's a period is not in num list negative one right so we're saying hey oops let's go back here we're saying hey if there's a plus sign and the last item of our list does not have a period if there's a period not in then we want to do this right otherwise don't do anything so let's go ahead and save this and run this guy one more time so we can go three point zero let's try this point three okay i didn't add a point there now we can go plus two point zero and we can add another point it doesn't do anything we can keep going and we can just keep going three point two point okay it doesn't add anything and we can equal and adds it all up and we can then point zero two keeps on going and everything works so pretty simple fix for that i just i was uh when i was writing that code yesterday sort of was doing it on the fly during the video and i didn't really stop to think it through so good catch in the comments section and that's really all there is to it so that's all for this video if you liked it be sure to smash the like button below and subscribe to the channel give me a thumbs up for the youtube algorithm and check out cody.com where you can use coupon code youtube1 to get thirty dollars on membership so you pay just forty nine dollars taxes all my courses over 47 courses hundreds of videos in the pds of all my best-selling coding books join over a hundred thousand students learn to code just like you my name is john elder from coding.com and i'll see you in the next video
Info
Channel: Codemy.com
Views: 4,830
Rating: undefined out of 5
Keywords: kivy calculator, kivy calculator tutorial, kivy calculator example, python kivy calculator, kivy decimals, kivy python tutorial, john elder codemy, build a calculator with python, calculator app, kivy tutorial #18, codemy.com, kivycoder.com, john elder kivy, python kivy tutorial windows, python kivy desktop app, kivy calculator decimal button, python kivy calculator decimal button
Id: AvbcELqNbx0
Channel Id: undefined
Length: 5min 56sec (356 seconds)
Published: Fri Dec 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.