
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如何讀取excel檔(.xlsx)?如何用欄標籤提取某一直行?df=pandas.read_excel() ; df[“欄標籤”] Python如何讀取excel檔(.xlsx)?如何用欄標籤提取某一直行?df=pandas.read_excel() ; df[“欄標籤”]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221109163631_39.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言