code 在論壇的顯示測試

因為以後會在這上面討論,並宜接貼出 code 。
看看貼出結果如何? (原程式有縮排)

import random
guess_list = [“石頭”, “剪刀”, “布”]
win_combination = [[“布”, “石頭”], [“石頭”, “剪刀”], [“剪刀”, “布”]]

while True:
computer = random.choice(guess_list)
people = raw_input(‘請輸入:石頭,剪刀,布\n’).strip()
if people not in guess_list:
continue
elif computer == people:
print (“平手,再玩一次!”)
elif [computer, people] in win_combination:
print (“電腦獲勝,再玩,人獲勝才能退出!”)
else:
print (“人獲勝!”)
break

唉! 縮排不見了,那這在上面討論可能會有問題。

那! 這樣呢 ?

import random
guess_list = ["石頭""剪刀""布"]
win_combination = [["布""石頭"], ["石頭""剪刀"], ["剪刀""布"]]

while True:
    computer = random.choice(guess_list)
    people = raw_input('請輸入:石頭,剪刀,布\n').strip()
    if people not in guess_list:
        continue
    elif computer == people:
        print ("平手,再玩一次!")
    elif [computer, people] in win_combination:
        print ("電腦獲勝,再玩,人獲勝才能退出!")
    else:
        print ("人獲勝!")
        break

這樣就可以了。
可能 SKY 版主要考慮裝個 外掛了。

版主可以考慮這裝看看。
https://highlightjs.org/

再測

public class CodeFormatting {
    public static void main(String[] args) {
        System.out.println("I can format code now!");
    }
}

原來上面的要這麼寫

```text 
public class CodeFormatting {
    public static void main(String[] args) {
        System.out.println("I can format code now!");
    }
 }
```

這樣就不用裝外掛了。

3個讚

再測
使用< pre> … < /pre> 也可以,只是 block 沒反白。

public class CodeFormatting {
    public static void main(String[] args) {
        System.out.println("I can format code now!");
    }
 }
1個讚
輸入```時,輸入視窗呈現會怪怪的,會看不到三個點,我還以為哪裡出錯了...
但在輸入三個`之後,右邊的 preview就會出現一條 bar,此時可輸入python、按 Enter,
接下來貼的程式碼就會被視為 python 的程式,關鍵字會有顏色/粗細的區別。
(也可以是其他任何程式語言的名稱、或是上面用的 text)
貼完程式之後,再按三下 ```,就完成程式區塊編輯。
from turtle import Turtle
POSITIONS = [(0, 0), (-20, 0), (-40, 0)]
DISTANCE = 20
UP = 90
DOWN = 270
RIGHT = 0
LEFT = 180


class Snake:

    def __init__(self):
        self.segs = []
        self.create_snake()
        self.head = self.segs[0]

    def create_snake(self):
        for pos in POSITIONS:
            snake_seq1 = Turtle("square")
            snake_seq1.penup()
            snake_seq1.goto(pos)
            snake_seq1.color('white')
            self.segs.append(snake_seq1)

Test ok.

2個讚
import random

cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
player_card=[]
pc_card = []
player_point = 0
pc_point = 0
def player_pick_a_card(card_amount):
    for x in range(card_amount):
        player_card.append(random.choice(cards))
    for point in player_card:
        player_point += point

def pc_pick_a_card(card_amount):
    for x in range(card_amount):
        pc_card.append(random.choice(cards))
    for point in player_card:
        pc_point += point

player_pick_a_card(2)
pc_pick_a_card(1)
print(f"Your card is {player_card}, current score:{player_point}")
print(f"Computer's first card :{pc_card[0]}")
def player_pick_a_card():
    player_card.append(random.choice(cards))
    #for point in player_card: 這樣寫會報錯 UnboundLocalError: local variable 'player_point' referenced before assignment
        #player_point += point
print(player_point)
def pc_pick_a_card():
    pc_card.append(random.choice(cards))

player_draw_a_card = input("Type 'y' to get another card, type 'n' to pass:\n").lower()

while player_point < 22:
    if player_draw_a_card =="y":
        player_pick_a_card()

測試
2個讚