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 | #1. def q1(): a = input ( "姓名" ) b = input ( "學號" ) c = input ( "班級" ) print (a,b,c) #2. def q2(): i = 1 while (i< 301 ): print (i) i + = 1 for i in range ( 1 , 301 ): print (i) #3. def q3(): sum = 0 for i in range ( 1 , 301 ): sum = sum + i print ( sum ) #4. # -*- coding: utf-8 -*- def q4(): name = input ( "Please enter a character string: " ) print ( "The string capitalized is " , end = "") for i in range ( 0 , 6 ): dec = int ( ord (name[i])) newstr = chr (dec - 32 ) print (newstr,end = "") print () #5. def q5(R): print (R * R * 3.14159265 ) |
2011年10月29日 星期六
100設計一甲_week6_模擬考答案
2011年10月25日 星期二
100設計一甲_week6_模擬考
1.使用input()函式輸入三個變數值(姓名 學號 班級)並輸出(Hint : input使用)
2.使用while以及for 各自印出從1到300的各個整數
3.用迴圈,計算1~300的總合(Hint : for while方式不限)
4.輸入6個字元的字串(英文小寫)轉成大寫輸出( Hint : input(),ord(),chr() )
5.使用自訂函式,計算圓面積,輸入R(半徑),R必須為函式之引數,試求面積(Hint : 需使用自訂函式,pi = 3.14159265)
2.使用while以及for 各自印出從1到300的各個整數
3.用迴圈,計算1~300的總合(Hint : for while方式不限)
4.輸入6個字元的字串(英文小寫)轉成大寫輸出( Hint : input(),ord(),chr() )
5.使用自訂函式,計算圓面積,輸入R(半徑),R必須為函式之引數,試求面積(Hint : 需使用自訂函式,pi = 3.14159265)
2011年10月19日 星期三
100設計一甲_week5
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 | #print()<---在python 3裡print是一個函數 所以必須加上括號 與之前python版本print不同 #input()<---輸入,輸入進來的型態為str #str()<---將()內轉換成字串 def ex1(): yourname = input ( "Please input your English name:" ) for i in range ( 0 , 4 ): print (yourname[i] + " ASCII value is " + str ( ord (yourname[i]))) #輸入4字元的字串 #ord()轉換()內字元所對應的ascii瑪 #chr()轉換()內數字所對應的字元<---須為int def ex2(): var = input ( "Please enter a four character string:" ) print ( "The string capitalized is " ,end = "") for i in range ( 0 , 4 ): print ( chr ( ord (var[i]) - 32 ),end = "") print () #mpg mile per gallon #求每一加侖所跑的里程 #輸入miledorve、gallon #miledorve/gallon=每加侖所跑的miles def ex3(): miledrove = float ( input ( "Please enter the miles you drove:" )) gallons = float ( input ("Please enter the gallons \ of gas you put in the tank:")) print ( "You got" , str (miledrove / gallons), "mpg on that tank of gas." ) #美元與外國幣值稅換 #以美國為主所以要查美國相對於各國的匯率 #rate此函式中代表匯率 #結果應該是 所要稅換的錢幣*匯率 def ex4(): dollars = float ( input ("What is the amount of US \ Dollars you wish to convert? ")) rate = float ( input ("What is the current exchange \ rate ( 1 ~US Dollar equals what in the Foreign Currency)? ")) print ( "The amount in the Foreign Currency is $%.2f" % (dollars * rate)) #以list來做9*9乘法表 #必須清楚for迴圈內的動作,變數的變動 #了解如何存取list內的內容 def ex5(): N = list ( range ( 1 , 10 )) #[1,2...9] X = list ( range ( 1 , 10 )) #[1,2...9] for i in N: for y in X: print (i, "*" ,y, "=" ,i * y,end = "\t" ) print () def ex6(): N = list ( range ( 20 , 31 )) #[20,21,22...30] X = list ( range ( 20 , 31 )) #[20,21,22...30] for i in N: for y in X: print ( "%3d * %3d =%4d" % (i,y,i * y),end = "\t" ) print () #店員找錢 #使用while迴圈 應找的錢(change) dollars(各種錢幣) pay(應找的硬幣數) #每一次迴圈 把當時所要找的錢除目前使用的硬幣 得到其商 就是這種硬幣要找的數量 #找完一次,必須要把找的錢與已給的錢(硬幣直*找的硬幣數量)相減 #迴圈直到要找的錢為0時,結束迴圈 def pay(): change = int ( input ( "input how much you should pay:" )) dollars = [ 100 , 50 , 10 , 5 , 1 ] pay = [ 0 , 0 , 0 , 0 , 0 ] i = 0 while (change! = 0 ): coin = change / / dollars[i] pay[i] = coin change = change - coin * dollars[i] i + = 1 print (pay) for num in range ( 0 , 5 ): print ( "%3d : %d 張" % (dollars[num],pay[num])) pay() |
2011年10月11日 星期二
100設計一甲_week4
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月4日 星期二
100設計一甲_week3
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 | import random def NumericOperations(num1,num2): print ( "num1=" ,num1, "num2=" ,num2) print ( "num1+num2=" ,num1 + num2) print ( "num1-num2=" ,num1 - num2) print ( "num1*num2=" ,num1 * num2) print ( "num1/num2=" ,num1 / num2) print ( "num1//num2=" ,num1 / / num2) #除法之商 print ( "num1%num2=" ,num1 % num2) #除法之餘數 print ( "num1**num2=" ,num1 * * num2) #num1的num2次方 def 猜數字(): 標準答案 = random.randint( 1 , 100 ) 你猜的數字 = int ( input ( "123:" )) 猜測次數 = 1 while 標準答案 ! = 你猜的數字: if 標準答案 < 你猜的數字: print ( "太大了,再猜一次! 加油" ) else : print ( "太小了,再猜一次!加油" ) 你猜的數字 = int ( input ( "請輸入您所猜的整數:" )) 猜測次數 = 猜測次數 + 1 print ( "猜對了!總共猜了" , 猜測次數, "次" ) def triangle(base,high): #area=base*high/2 return (base * high / 2 ) def tri(base,high): h = (base * base + high * high) * * 0.5 print (h) #return (h) def squre(x,n): ans = 1 while (n> 0 ): ans = ans * x n = n - 1 return (ans) print (squre( 2 , 10 )) #print(2**10) def ex1(x,n): ans = 0 while x< = n: ans = ans + x x = x + 1 return (ans) print (ex1( 1 , 100 )) #1+2+3+...+99+100 #one day one apple def apple(): ans = "apple" guess = "" count = 0 while (ans! = guess and count< 10 ): print ( "一天一??,醫生遠離你,只能猜十次喔" ) ans = input ( "ans:" ) count = count + 1 if (ans! = guess): print ( "十次都沒答對......." ) else : print ( "你答對了,猜了" ,count, "次,答案為一天一" ,ans, "醫生遠離你" ) #apple() print (triangle( 3 , 4 )) print (tri( 3 , 4 )) |
訂閱:
文章 (Atom)