發表文章

陳威暟期末考為python貪吃蛇增加速度

圖片
from tkinter import * import random GAME_WIDTH,GAME_HEIGHT = 800, 400 SPEED = 1000 #時間單位千分之一 SPACE_SIZE, BODY_PARTS= 50, 3 #左邊變數 assigning value SNAKE_COLOR = ["red","orange","yellow","green","blue","indigo", "purple"] FOOD_COLOR = "white" BACKGROUND_COLOR = "black" class Snake: def __init__(self): self.body_size = BODY_PARTS self.coordinates = [] self.squares = [] for i in range(0, BODY_PARTS): self.coordinates.append([0, 0]) for x, y in self.coordinates: i = random.randint(0,6) square = canvas.create_rectangle(x, y, x + SPACE_SIZE, y + SPACE_SIZE, fill=SNAKE_COLOR[i], tag="snake", width=20,outline='blue') self.squares.append(square) class Food: def __init__(self): x = random.randint(0, int(GAME_WIDTH / SPACE_SIZE)-1) * SPACE_SIZE y = random.randint(0, int(GAME_HE...

陳威暟Javascript在瀏覽器就可以執行不需要VS Code

圖片
Javascript在網頁就可以執行不需要開啟Spyder 陳威暟執行 我人執行

陳威暟python全域變數global和判斷if

圖片
from tkinter import * #或者import tkinter as tk import math#輸入數學MATH函式庫 tk = Tk() #建構視窗名為tk tk.geometry('1200x400')#視窗 寬1200像素 tk.title(" 陳威暟python tkinter三角函數") canvas = Canvas(tk, width=1200, height=400, bg='PINK') canvas.grid(row=0,column=0,padx=5,pady=5,columnspan=3) delay=2 # milliseconds, 1/1000秒 x1,y1,z1=0,200,10#python特徵,多變數=對等值 h=190 #上下範圍,相當於數學1到-1 def LH(): global x1, y1, z1#global全球,local當地 x2 = x1 + 1 #換到下個+1 y2=200 - h*math.sin(0.02*x2) z2=200 - h*math.cos(0.02*x2) L1=canvas.create_line(x1,y1,x2,y2,fill='BLUE',width=10) L2=canvas.create_line(x1,z1,x2,z2,fill='yellow',width=10) if (x2

陳威暟python輸入tkinter和math函式庫

圖片

陳威暟python金融常識測驗

  class Financial :     def __init__ ( self , number , q , a , b , c , d , ans ):         self . number , self . q , self . ans = number , q , ans         self . a , self . b , self . c , self . d = a , b , c , d f = open ( 'C:/Users/user/Downloads/金融常識.txt' , 'r' , encoding = 'utf-8' ) read = f . readlines () #read = f.read() f . close () List = [] Answer = ( 4 , 4 , 3 , 4 , 3 , 2 , 3 , 3 , 4 , 2 , 4 , 4 , 4 , 3 , 4 , 2 , 3 , 1 , 1 , 2 , 1 , 2 , 3 , 3 , 1 , 3 , 4 , 4 , 3 , 4 , 1 , 4 , 3 , 2 , 4 , 2 , 2 , 3 , 2 , 4 , 1 , 4 , 1 , 1 , 4 , 3 , 1 , 2 , 4 , 1 , 2 , 1 , 4 , 4 , 4 , 1 , 4 , 2 , 1 , 3 , 3 , 1 , 4 , 4 , 3 , 2 , 2 , 2 , 4 , 4 , 1 , 3 , 3 , 1 , 2 , 4 , 1 , 3 , 4 , 4 , 2 , 4 , 4 , 3 , 4 , 1 , 3 , 2 , 3 , 2 , 3 , 2 , 2 , 2 , 4 , 4 , 4 , 1 , 1 , 2 , 2 , 4 , 4 , 1 , 4 , 1 , 4 , 4 , 4 , 2 , 1 , 1 , 2 , 1 , 2 , 1 , 2 , 2 , 3 , 3 , 3 , 4 , 2 , 1 , 1 , 1 , 1 , 2 , 2 , 1 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 3 , 4 , 4 , 1 , 1 , 2 ,...