
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.DataFrame去重:df.drop_duplicates() 與 df[~df.duplicated()] 的等價、差異與最佳實踐 一文搞懂Python pandas.DataFrame去重:df.drop_duplicates() 與 df[~df.duplicated()] 的等價、差異與最佳實踐](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/08/20250808202701_0_66f9bc.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 如何判斷字符串內容是否為數字(整數或浮點數)? isinstance( eval( entry.get() ), (float, int) ) ; str.isdigit() #不包括小數點和負號 ; try~ except ValueError~ ; 正則表示法 regular expression ; pattern = ‘^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$’ Python: 如何判斷字符串內容是否為數字(整數或浮點數)? isinstance( eval( entry.get() ), (float, int) ) ; str.isdigit() #不包括小數點和負號 ; try~ except ValueError~ ; 正則表示法 regular expression ; pattern = ‘^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$’](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2023/05/20230512152430_3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







近期留言