python answer with 2 decimals code example

Example 1: how to print a float with only 2 digits after decimal in python

#to round floats in Python you can use the "round" function. ex:

tax = 34.4563
tax = round(tax, 2)

#the number 2 at the end is how many digits are rounded.

#the variable "tax" would now be: 34.46

Example 2: round off float to 2 decimal places in python

answer = str(round(answer, 2))

Example 3: how to print answer 2 decimal places in python 3

print("{0:.2f}".format(sum(student_marks[query_name])/3))

Example 4: how to multiply 2 decimals together and get answer back in python

import kivy # todo import buttons from kivy and add clear number button on bottum of program and then bind button
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
import math

class MyGrid(GridLayout):
    def __init__(self, **kwargs):
        super(MyGrid, self).__init__(**kwargs)
        self.cols = 1

        self.inside = GridLayout()
        self.inside.cols = 2

        self.inside.add_widget(Label(text="NUM1: "))
        self.num1 = TextInput(multiline=False)
        self.inside.add_widget(self.num1)

        self.inside.add_widget(Label(text="NUM2: "))
        self.num2 = TextInput(multiline=False)
        self.inside.add_widget(self.num2)

        self.inside.add_widget(Label(text="ANSWER: "))
        self.answer = TextInput(multiline=False)
        self.inside.add_widget(self.answer)


        self.add_widget(self.inside)
        self.clear = Button(text="Clear", font_size=20)
        self.clear.bind(on_press=self.pressed)
        self.add_widget(self.clear)


    def pressed (self, instance):
        num1 = self.num1.text
        num2 = self.num2.text
        answer = self.answer.text

        print("num1:", num1, "num2:", num2, "answer:", answer)

	 def numbermultiplier(num1, num2):
      ans = num1 * num2
      return ans
    print(numbermultiplier(12700.00,5.63))	

class MyApp(App):
    def build(self):
        return MyGrid()


if __name__ == "__main__":
    MyApp().run()


# Hi there here is my code ??What I want is to multiply num1 and num2 together in the text box and for it to display the answer in the answer box and if I press clear to clear the whole box