
code:
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 18 19:40:26 2023
@author: SavingKing
"""
s1= input("請輸入第一個二進位數字:\t")
s2= input("請輸入第二個二進位數字:\t")
s1_0b = "0b"+s1
s2_0b = "0b"+s2
int1 = int(s1_0b,2)
int2 = int(s2_0b,2)
sum1 = int1+int2
print(f"{int1} + {int2} = {sum1}")
print(f"{sum1:08b}")
#因為題目的輸出剛好8位數的第一位數都是1
#也可使用bin(),會省略前導0 ,
#但以f string解題為佳輸出結果:

推薦hahow線上學習python: https://igrape.net/30afN






![Python Pandas GroupBy 的 size 陷阱:為什麼你的計數結果總是不對?如何計算重複次數? duplicates = df.duplicated( subset = [‘name’] ) Python Pandas GroupBy 的 size 陷阱:為什麼你的計數結果總是不對?如何計算重複次數? duplicates = df.duplicated( subset = [‘name’] )](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/06/20250609143758_0_53821c.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS] Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS]](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260210083748_0_a7d9bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言