a. remainder_带有Python示例的math.remainder()方法

a. remainder

Python math.remainder()方法 (Python math.remainder() method)

math.remainder() method is a library method of math module, it is used to find the remainder of given numbers, it accepts two numbers (integer or float) and returns the remainder of the first number with respect to the second number in the float.

math.remainder()方法math模块的库方法,用于查找给定数字的余数,它接受两个数字(整数或浮点数),并相对于第二个数字返回第一个数字的余数浮动。

Note: math.remainder() method is available in the new version of Python – Python 3.7

注意: math.remainder()方法在新版本的Python – Python 3.7中可用

Syntax of math.remainder() method:

math.remainder()方法的语法:

    math.remainder(a, b)

Parameter(s): a, b – the numbers whose remainder needs to be calculated.

参数: a,b –需要计算其余数的数字。

Return value: float – it returns a float value that is the remainder of a with respect to b.

返回值: float –返回一个浮点值,该值是a相对于b的余数。

Example:

例:

    Input:
    a = 10
    b = 7

    # function call
    print(math.remainder(a, b))

    Output:
    3.0

Python代码演示math.remainder()方法的示例 (Python code to demonstrate example of math.remainder() method)

# python code to demonstrate example of 
# math.remainder() method

# importing math module
import math

# numbers
a = 10
b = 7
# finding remainder
print(math.remainder(a,b))

a = 10.2
b = 7.1
# finding remainder
print(math.remainder(a,b))

Output

输出量

3.0
3.0999999999999996


翻译自: https://www.includehelp.com/python/math-remainder-method-with-example.aspx

a. remainder

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您可以使用Python中的tkinter模块来创建一个GUI界面的计算器,具有您提到的所有功能。 以下是一个简单的示例代码: ``` from tkinter import * def clear(): display.delete(0, END) def button_click(number): current = display.get() display.delete(0, END) display.insert(0, str(current) + str(number)) def add(): first_number = display.get() global f_num global math math = "addition" f_num = float(first_number) display.delete(0, END) def subtract(): first_number = display.get() global f_num global math math = "subtraction" f_num = float(first_number) display.delete(0, END) def multiply(): first_number = display.get() global f_num global math math = "multiplication" f_num = float(first_number) display.delete(0, END) def divide(): first_number = display.get() global f_num global math math = "division" f_num = float(first_number) display.delete(0, END) def convert(): decimal_number = int(display.get()) base = int(input("Enter the desired base: ")) converted_number = '' while decimal_number > 0: remainder = decimal_number % base converted_number = str(remainder) + converted_number decimal_number = decimal_number // base display.delete(0, END) display.insert(0, converted_number) def equal(): second_number = display.get() display.delete(0, END) if math == "addition": display.insert(0, f_num + float(second_number)) if math == "subtraction": display.insert(0, f_num - float(second_number)) if math == "multiplication": display.insert(0, f_num * float(second_number)) if math == "division": display.insert(0, f_num / float(second_number)) root = Tk() root.title("Calculator") display = Entry(root, width=35, borderwidth=5) display.grid(row=0, column=0, columnspan=4, padx=10, pady=10) button_1 = Button(root, text="1", padx=40, pady=20, command=lambda: button_click(1)) button_2 = Button(root, text="2", padx=40, pady=20, command=lambda: button_click(2)) button_3 = Button(root, text="3", padx=40, pady=20, command=lambda: button_click(3)) button_4 = Button(root, text="4", padx=40, pady=20, command=lambda: button_click(4)) button_5 = Button(root, text="5", padx=40, pady=20, command=lambda: button_click(5)) button_6 = Button(root, text="6", padx=40, pady=20, command=lambda: button_click(6)) button_7 = Button(root, text="7", padx=40, pady=20, command=lambda: button_click(7)) button_8 = Button(root, text="8", padx=40, pady=20, command=lambda: button_click(8)) button_9 = Button(root, text="9", padx=40, pady=20, command=lambda: button_click(9)) button_0 = Button(root, text="0", padx=40, pady=20, command=lambda: button_click(0)) button_clear = Button(root, text="Clear", padx=80, pady=20, command=clear) button_convert = Button(root, text="Convert", padx=76, pady=20, command=convert) button_add = Button(root, text="+", padx=39, pady=20, command=add) button_subtract = Button(root, text="-", padx=41, pady=20, command=subtract) button_multiply = Button(root, text="x", padx=40, pady=20, command=multiply) button_divide = Button(root, text="/", padx=41, pady=20, command=divide) button_equal = Button(root, text="=", padx=91, pady=20, command=equal) button_1.grid(row=3, column=0) button_2.grid(row=3, column=1) button_3.grid(row=3, column=2) button_4.grid(row=2, column=0) button_5.grid(row=2, column=1) button_6.grid(row=2, column=2) button_7.grid(row=1, column=0) button_8.grid(row=1, column=1) button_9.grid(row=1, column=2) button_0.grid(row=4, column=0) button_clear.grid(row=4, column=1, columnspan=2) button_convert.grid(row=5, column=0, columnspan=2) button_add.grid(row=1, column=3) button_subtract.grid(row=2, column=3) button_multiply.grid(row=3, column=3) button_divide.grid(row=4, column=3) button_equal.grid(row=5, column=2, columnspan=2) root.mainloop() ``` 这将创建一个简单的计算器GUI,您可以单击按钮执行所需的操作。 同样,十进制转换功能只能在命令行上使用,因为它需要输入所需进制的值。 您也可以在GUI中添加一个输入框以获取所需进制,但这超出了此示例的范围。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值