1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #有關進位 #98436145310十進位 #0123456789ABCDEF十六進位 #0101101010二進位 #print(0b01101100) #print(hex(108)) #print(0x6c) #print(bin(108)) #print(bin(108)) def eight_bit(mystr): return ( int (mystr[ 0 ]) * 2 * * 7 + int (mystr[ 1 ]) * 2 * * 6 + int (mystr[ 2 ]) * 2 * * 5 + int (mystr[ 3 ]) * 2 * * 4 + int (mystr[ 4 ]) * 2 * * 3 + int (mystr[ 5 ]) * 2 * * 2 + int (mystr[ 6 ]) * 2 * * 1 + int (mystr[ 7 ]) * 2 * * 0 ) #print(eight_bit("01101100")) #請編寫一個簡單的互動式程式, 程式列印出”請輸入您的姓名”後 #, 等待使用者輸入. 使用者輸入姓名 XXX 後, 程式列印出”XXX, 歡迎進入程式語言的世界”. def ex0(): var = 1010.2011 print ( "%20d %5.1f %s" % (var,var,var)) def ex1(): username = input ( "請輸入您的姓名:" ) print (username, "歡迎進入程式語言的世界." ) #請配合練習 1.14 編寫一個能夠列印從 1 累加到 100 總和的程式. def ex2(): total = 0 for num in range ( 1 , 100 + 1 ): total = total + num print ( "The total is" ,total) def ex2_1(): total = 0 num = 1 while (num< 101 ): total = total + num num = num + 1 print ( "The total is" ,total) #請編寫一個能夠在列印 “請問由 1 累加到哪一個大於 1 的整數?”, 後讀取使用者輸入的整數, #並列印出從 1 累加到”某整數”總和的程式. def ex3(): usernum = int ( input ( "請問由1累加到哪一個大於1的整數:" )) if (usernum< 1 ): print ( "不符合要求" ) else : total = 0 for num in range ( 1 ,usernum + 1 ): total = total + num print ( "1累加到" ,usernum, "總和:" ,total) #請問如何在使用者需要退出累加程式之前, 可以”一直”輸入累加極限值, 並且進行數值的累加運算? def ex1_19_1(): username = input ( "Please enter your name:" ) if (username is not None ): for alphabet in username: print (alphabet, "ASCII value is" , ord (alphabet)) def ex1_19_2(): username = input ( "Please enter your name:" ) print ( "The string capitalized is" ) for alphabet in username: num = ord (alphabet) - 32 print ( chr (num),end = "") print () # Date NTD/USD #2011-10-07 30.493 #example iPhone 4S 16GB 199美元 #匯率稅換 US->$ def usconvert(): dollar = float ( input ( "What is the amount of US Dollars you wish to convert:" )) exchange = float ( input ( "What is the current exchange rate:" )) print ( "The amount in the Foreign Currency is $" ,dollar * exchange) #底下是有關1.8之問題 """ #1.8Q4 print(eight_bit("01101100")) #1.8Q5 print(hex(108)) #1.8Q6 print(bin(-62)) #1.8Q7 print(chr(62)) #print(hex(10)) """ #呼叫匯率稅換函式usconvert() #usconvert() #有問題請在底下留言,謝謝... |
2011年10月11日 星期二
100設計一甲_week4
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言