2011年11月29日 星期二

100設計一甲_week12 小考答案

exam1.c
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
#include<stdio.h>
void q1(){
int i;
int num1=0,num3=0;
int total=0;
for(i=399;i<=8993;i++){
num1=i%10;
num3=(i/100)%10;
if((num1+num3)==11){
total+=i;
}
}
printf("%d\n",total);
}
void q2(){
int i;
int num1=0,num3=0;
int total=0;
for(i=359;i<=8691;i++){
if(i%7==0 && i%2==0){
total+=i;
}
}
printf("%d\n",total);
}
void q3(){
int i;
int num1=0,num3=0;
int total=0;
for(i=95;i<=8505;i++){
if(i%14!=0){
total+=i;
}
}
printf("%d\n",total);
}
void q4(){
int i=0,j=0;
int total=0;
for(i=473;i<=8393;i++){
int count=0;
j=i;
while(j!=0 && count==0){
if(j%10==3||j%10==6||j%10==8)
count++;
j=j/10;
}
if(count!=0)
total+=i;
}
printf("%d\n",total);
}
void q5(){
int i;
int num1=0,num3=0;
int total=0;
for(i=486;i<=8817;i++){
num1=i%10;
num3=(i/100)%10;
if((num1*num3)==16)
total+=i;
}
printf("%d\n",total);
}
int main(){
q1();
q2();
q3();
q4();
q5();
return 0;
}
exam2.py
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
def q1():
total=0;
for i in range(399,8993+1):
num1=i%10;
num3=int(i/100)%10;
if((num1+num3)==11):
total+=i;
print(total)
def q2():
total=0
for i in range(359,8691+1):
if(i%7==0 and i%2==0):
total+=i
print(total)
def q3():
total=0
for i in range(95,8505+1):
if(i%14!=0):
total+=i
print(total)
def q4():
total=0
for 索引 in range(473,8393+1):
if str(索引).find("3") != -1 or str(索引).find("6") != -1 or str(索引).find("8") != -1:
total+=索引
print(total)
def q5():
total=0;
for i in range(486,8817+1):
num1=i%10;
num3=int(i/100)%10;
if((num1*num3)==16):
total+=i;
print(total)
q1()
q2()
q3()
q4()
q5()

100設計一甲_week12

example1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int main(){
int num1 = 123;
float num2 = 3.14159;
double num3 = 3.14159e-3;
char name1[6] = "hello";
char name2[6]={'h','e','l','l','o','\0'};
/*
字串最後必須加上結束\0字元,代表字串結束
hello 為五個字元 但最後必須加上\0,所以為六個字元。
*/
printf("%d\n", num1);
printf("%f\n", num2);
printf("%e\n", num3);
printf("%s\n", name1);
printf("%s\n", name2);
printf("%c\n", name1[1]);
printf("%c\n", name2[1]);
return 0;
}

Python Module in C 動態教學(Save as...)

Python_module.7z

tcc_gnuplot3.7z

2011年11月22日 星期二

100設計一甲_week11

example1.c
1
2
3
4
5
#include<stdio.h>
int main(){
printf("hello c!\n");
return 0;
}
example2.c
1
2
3
4
5
6
7
8
9
#include<stdio.h>
int main(){
printf("hello c!\n");
int i=0;
for(i=0;i<10;i++){
printf("%d\n",i);
}
return 0;
}
example3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
int main(){
int i=0;
for(i=0;i<=100;i++){
if(i<=40){
printf("C score:%d\n",i);
}
else if(i<=70){
printf("B score:%d\n",i);
}
else{
printf("A score:%d\n",i);
}
}
return 0;
}
/*
班級從1到最後一號
假如號碼是偶數 後面請加even
假如號碼是奇數 後面請加odd
依次序印出
*/

2011年11月15日 星期二

100設計一甲_week10

tkinter.py
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
#coding: utf-8
from tkinter import *
# 導入所有的數學函式
from math import *
# 導入數學函式後, 圓周率為 pi
# deg 為角度轉為徑度的轉換因子
deg = pi/180.
frame=Frame()
frame.master.title("繪圖範例")
frame.pack()
canvas = Canvas(width=800, height=800, bg='white')
canvas.pack(expand=YES, fill=BOTH)
def plotline():
for i in range(0, 500, 50):
canvas.create_line(0, i, 500, i)
#canvas.create_line(i, 0, i, 500)
def polygon(r=100,cx=150,cy=150,offset=30):
for i in range(270,270+360,offset):
x0=cx+r*cos(i*deg)
y0=cy+r*sin(i*deg)
x1=cx+r*cos((i+offset)*deg)
y1=cy+r*sin((i+offset)*deg)
canvas.create_line(x0,y0,x1,y1)
def plot():
for i in range(0,600,30):
canvas.create_line(400-i,350-i, 500+i,350-i)
canvas.create_line(500+i,350-i, 500+i,450+i)
canvas.create_line(500+i,450+i, 400-i,450+i)
canvas.create_line(400-i,450+i, 400-i,350-i)
plotline()
polygon()
mainloop()
find.py
1
2
3
4
5
6
7
8
9
10
11
12
s="applenkajkljkhapplejgaa"
pos=0
count=0
while(1):
pos=s.find("apple",pos)
if(pos==-1):
break
pos=pos+1
count=count+1
print(count)
print(s.count("apple"))

2011年11月8日 星期二

100設計一甲_week7

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
#Q1
#輸入一字串10字元將字串內容中的英文,小轉大寫,其餘照常印出。
def q1():
string=input("輸入一字串10字元:")#輸入字串
for i in range (0,len(string)):#len()測量字串長度
#判斷字元是否在需轉換範圍內
if(ord('A')<=ord(string[i])<=ord('Z')):#ord 將字元轉ascii dec
print(chr(ord(string[i])+32),end="")#chr 將整數轉成字元
#其餘正常印出
else:
print(string[i],end="")
#Q2
#你拿到一個整數(4位數),卻忍不住想把每個位數都乘在一起。
def q2():
total=1
num=input("輸入數字 n:")
for i in range(0,len(num)):
total*=int(num[i])#轉成整數
print(total)
#Q3
#輸入身高(cm)體重(kg),求BMI值並依照其BMI值印出體重分級與BMI,BMI需印至小數第一位。
def q3():
weight=float(input("輸入體重(kg)"))
heigh=float(input("輸入身高(cm)"))/100 #cm轉m 除100
BMI=weight/(heigh*heigh)
if(BMI < 18.5): #判斷BMI之範圍
print("%.1f 體重過輕"%(BMI))
elif(18.5 <= BMI <24):
print("%.1f 正常範圍"%(BMI))
elif(24 <= BMI < 27):
print("%.1f 過 重"%(BMI))
elif(27 <= BMI < 30):
print("%.1f 輕度肥胖"%(BMI))
elif(30 <= BMI < 35):
print("%.1f 中度肥胖"%(BMI))
else:
print("%.1f 重度肥胖"%(BMI))
#Q4
#由1到100,印出其中只含有3,不含有4,6,9的數值。
def q4():
for 索引 in range(1,101):
if str(索引).find("3") != -1:
if str(索引).find("4") == -1 and str(索引).find("6") == -1 and str(索引).find("9") == -1:
#find()找尋字串中是否有符合的字元 如果沒有則為-1 有則為符合字元的位置,底下q4find()函式為測試find的使用例子。
print(索引)
#Q5
#平方公尺轉坪數,輸入幾平方公尺,輸出幾坪。
#公式:坪數 = 平方公尺 * 0.3025 (固定)
def q5():
平方公尺=float(input("輸入幾平方公尺:"))#輸入可能帶有小數,因此轉為浮點數。
print(平方公尺*0.3025)
def q4find():
for i in ["taiwan","people"]:
print(i.find("w"))