Python 程序读取两个数字并打印其商和余数
当需要读取两个数字并打印它们除法后的商和余数时,可以使用‘//’和‘%’运算符。
以下对其进行演示 -
示例
first_num = int(input("Enter the first number..."))
second_num = int(input("Enter the second number..."))
print("The first number is ")
print(first_num)
print("The second number is ")
print(second_num)
quotient_val = first_num//second_num
remainder_val = first_num%second_num
print("The quotient is :")
print(quotient_val)
print("The remainder is :")
print(remainder_val)输出
Enter the first number...44 Enter the second number...56 The first number is 44 The second number is 56 The quotient is : 0 The remainder is : 44
说明
第一个和第二个数字作为输入从用户获取。
它们显示在控制台上。
使用‘//’运算符求商。
使用‘%’运算符求余数。
运算输出分别赋值给两个变量。
这作为输出显示在控制台上。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP