在這個簡單的 python 程序中,我們需要找到商和餘數。這是一個初級 python 程序。
要理解這個例子,您應該了解以下 Python 編程主題:
- Python 語法
- Python 運算符
- Python 安裝和設置
python 中如何求商和餘數?
這個簡單的 python 程序是關於 python 中算術運算的除法。這裡我們需要用給定的數除一個數,並列印出商和餘數。例如,考慮兩個數字 125 和 7,讓我們用 7 除 125,得到的商是 17,提醒是 6。
為了應用 python 語言中的除法邏輯,我們接受來自用戶的兩個數字,並分別計算商和餘數。為了求商,我們用給定的數除以該數,並將該值保存為可變商。其次,我們使用 Mod 運算符計算餘數,並將該值保存為餘數。最後,使用 python 基本方法和語法列印商和餘數。
演算法
步驟 1: 接受用戶使用輸入法輸入的兩個除法數字,並使用 Python 編程語言中的int()
將字元串轉換為整數。
STEP 2: 保存該數除以給定數後的商的值。
步驟 3: 使用模塊操作符保存餘數的值。
步驟 4: 使用 python 中的列印列印商和餘數的值。
Python 源代碼
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
quotient=a//b
remainder=a%b
print("Quotient is:",quotient)
print("Remainder is:",remainder)
輸出
Enter the First number : 125
Enter the Second number : 7
Quotient is : 17
Reminder is : 6
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/284637.html