# 軟實作業 ```=python import numpy as np import matplotlib.pyplot as pl x = np.linspace(-np.pi,np.pi) threshold = 0 y = [] for value in x: if value >= threshold: y.append(1) else: y.append(0) pl.figure() pl.scatter(x,y,marker='o') pl.show() import numpy as np import matplotlib.pyplot as pl x = np.linspace(-np.pi,np.pi) threshold = 0 y = [] for value in x: if value >= threshold: y.append(value) else: y.append(0) pl.figure() pl.scatter(x,y,marker='o') pl.show() import numpy as np import matplotlib.pyplot as pl x = np.linspace(-np.pi,np.pi) threshold_l = 0 threshold_h = 1 y = [] for value in x: if threshold_h >= value >= threshold_l: y.append(value) elif value > threshold_h: y.append(1) else: y.append(0) pl.figure() pl.scatter(x,y,marker='o') pl.show() import random S = list(range(60,101)) N = 20 scores = [] for i in range(N): s = random.choice(S) scores.append(s) grade = [] for score in scores: if score >= 95: g = 'A' elif score >= 90: g = 'B' elif score >= 85: g = 'C' elif score >= 80: g = 'D' elif score >= 75: g = 'E' else: g = 'F' grade.append(g) for i in range(len(grade)): print(scores[i],grade[i]) import random Dice = [i for i in range(1,7)] while True: p = [] times = 3 for i in range(times): dice = random.choice(Dice) p.append(dice) print("dices",p) a = set(p) if len(a) == 1: print('score is 7') break elif len(a) == 2: for j in a: if p.count(j) == 1: print(j) break else: print(len(a), 'different points.') continue ```