Math Calculator Buttons With eval() - Python Kivy GUI Tutorial #19

Math Calculator Buttons With eval() - Python Kivy GUI Tutorial #19

Codemy.com

3 года назад

15,151 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@HarikrishnanSrinivasan
@HarikrishnanSrinivasan - 07.12.2020 20:21

First

Ответить
@durazno45
@durazno45 - 07.12.2020 21:43

Good job master!!!

Ответить
@joephinazee5422
@joephinazee5422 - 07.12.2020 23:09

I look forward to taking lunch breaks just to watch your videos. I love all your teachings! Also, I completed my percentage button. Probably use some tweaking, but it works as is.

def percentage(self):

if self.answer == '0':
pass
else:
self.answer = self.answer / 100
self.ids.calc_input.text = str(self.answer)
self.answer = '0'

Ответить
@hiwab41
@hiwab41 - 07.12.2020 23:31

Your helping alot thx 😊😊😊💖

Ответить
@sparshbatta7070
@sparshbatta7070 - 08.12.2020 18:42

Hands Down the Best Tutorial Ever !! No perplexing, no confusions just a plain, easy and nice approach to teach the stuff !! Keep up the good work.👍👍👌👌😎😎

Ответить
@franciscocardozo9665
@franciscocardozo9665 - 08.12.2020 23:56

Hi John,thanks for uploading these videos. I really learn a lot with them
I have a question: can you import "special" functions like sin,cos,exponential,etc and place them in the calculator?

Ответить
@nejinii1353
@nejinii1353 - 22.12.2020 05:31

Funny thing in programming world is this surprised face when you don't expect something to work, or like in this case work so well xD

Thank you very much for presenting us these things in such simple manner, and i'm glad your dog is fine!

Ответить
@amargluhic9026
@amargluhic9026 - 28.01.2021 01:00

i love the kivy playlist, i recommend adding a basic if statement because with eval() anyone can evaluate python code and mess up your computer. something like this should work

def calculate(self):
v1 = self.ids.calc_input.text

allowed = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', 'x', '/', '%', '.', '(', ')'
}
a = [item for item in list(v1) if item in allowed]
if len(a) == len(v1):
self.ids.calc_input.text = str(eval(v1))
return
print('you're trying to do something else :(')

let me know if i missed any characters :P

Ответить
@elenaab4356
@elenaab4356 - 17.02.2021 18:20

hello , I change the color's button in kivy file whit canvas , but I want to change the colour of button when pressing this , but I can't .
can you help me , thank you sir :)

Ответить
@playerandroidtutoriais8905
@playerandroidtutoriais8905 - 10.04.2021 06:27

Another alternative for division:

if '/' in prior:
num_list = prior.split('/')
answer = 1

for number in num_list:
answer = int(num_list[0]) / int(num_list[1])


self.ids.calc_input.text = str(answer)

Ответить
@DamienMurtagh-Galea
@DamienMurtagh-Galea - 11.04.2021 13:42

Hi John

Love all the work you do. I'm an IT teacher and you're the #1 place I send my students to understand Python GUI programming.

Mate, I seem to get really weird values when I divide by 3. For example 10/3 will give 335, 7/3 = 335. 10/6 = 667. Any ideas what I've done wrong?

Ответить
@yahyaa4499
@yahyaa4499 - 03.05.2021 09:35

There is an error
Can you please try 6/9

Ответить
@عالمالبرمجةالعربي
@عالمالبرمجةالعربي - 24.05.2021 11:54

hi teacher the you wolf is very beautiful

Ответить
@christopherjonesramos3655
@christopherjonesramos3655 - 08.06.2021 15:12

I've been watching your videos. And I seem to not be able to figure out how to clear the text input automatically after the answer has been displayed, when the user will enter another set of numbers, without pressing the C button.

Ответить
@saadahmedkhan3897
@saadahmedkhan3897 - 16.06.2021 08:08

Me watching this video. Suddenly a load shedding occars . Wi-Fi turn off. I make the calculator without watching this video. Yay!

Ответить
@miladsmaeeli9119
@miladsmaeeli9119 - 29.07.2021 15:51

Thank you very much. I've learned many things from your series...

Ответить
@gregnstuff1118
@gregnstuff1118 - 16.08.2021 21:56

Thanks for the lesson and mad props to all the calculator creators out there. It it is fun to see how easy one missed function can break/fix a whole lot of things.

Ответить
@swastiksarkar
@swastiksarkar - 28.10.2021 16:37

I recently started learning Kivy and someone said that learning UI framework in python is just a waste of time. Is this true?

Ответить
@unclebuddy
@unclebuddy - 16.01.2022 22:19

Good Kivy tutorial. Division needs some work. When the answer goes on forever past the decimal, eval() works, but in the calculator, what's displayed is just part of the answer, like the last three digits of 0.8333333333333334 for "5/6". If you print the answer it's right but it doesn't display right in the calculator. Solved by using the round() function built into Python.

Ответить
@abhishekranjan7143
@abhishekranjan7143 - 04.06.2022 20:02

I am getting below error message during execution with eval() function . May kindly please help fixing the issue.
AttributeError: 'super' object has no attribute '__getattr__'

Ответить
@paulushimawan5196
@paulushimawan5196 - 11.08.2022 19:00

I challenge all of you to code overflow error. The logic is pretty simple. If the answer is more than 12 digits, it will output an error, just like standard calculator. For example, 99999999*99999999 = Error.

Ответить
@erindeerhart5538
@erindeerhart5538 - 01.02.2023 20:46

Maybe you fix this in a later video, but a subtraction operator will simply be deleted from the text input if you press the +/- button. So "3*5-10" will become "3*510".

Do I have that right?

Ответить
@msvisoko9105
@msvisoko9105 - 15.02.2023 18:51

Percentage function with '+' and '-' operations. For example: 90 + 10% of 90 = 99. It can be modified further in similar way:
def percentage(self):
global result, result2
prior = self.ids.calc_input.text
if '+' in prior:
result = prior.split('+')
else:
result2 = prior.split('-')
if prior == '0':
pass
elif '-' in prior and len(result2) == 2:
result3 = float(result2[0]) - (float(result2[0]) / 100)*float(result2[-1])
self.ids.calc_input.text = str(round(result3, 3))
elif '+' in prior and len(result) == 2:
result4 = float(result[0]) + (float(result[0]) / 100)*float(result[-1])
self.ids.calc_input.text = str(round(result4, 3))

Ответить