Python教學 | W3School | 初學者好用python工具 https://thonny.org/
turtle 龜圖學(繪圖工具) https://docs.python.org/zh-tw/3/library/turtle.html
請使用 https://replit.com/languages/python3 練習Python程式
print('Hello, world!')
a = input('請輸入你的姓名')
print('Hello' , a)
a=10
b=2
print(a+b)
print(a-b)
print(a*b)
print(a/b) #a除b的商數
print(a%b) #a除b的餘數
print(a**b) #a的b次方
請使用 https://replit.com/languages/python3 練習Python程式
也可以使用Python Tutor練習及研究程式數值變化
for i in range(1,5,1):
print('*'*i)
j=2
for i in range(1,6,2):
print(' '*j, '*'*i,end='')
j = j-1
print()
turtle 龜圖學(繪圖工具) https://docs.python.org/zh-tw/3/library/turtle.html
請使用Thonny Python IDE工具練習用turtle繪圖
也可用google 帳號登入使用 https://replit.com/languages/python3 繪圖
請使用 Python Tutor練習及研究程式數值變化
n系統先隨機產生4個0∼9不重複的數字,再讓使用者輸入4個數字,再將輸入的數字與答案進行比對後,用「幾A幾B」的方式提示使用者是否正確。其中:A 代表數字正確,且位置正確;B 代表數字正確,但位置錯誤。n使用者有輸入的8次機會中, 如果沒猜到正確數字,則遊 戲結束,並顯示「作答已達 8次,遊戲結束,目標數字是⋯」;n如果在8次機會中,使用者輸入的數字完全正確, 則出現「您答對了,數字是⋯」。
from random import randintanswer = ''count_a = 0count_b = 0times = 1numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]random_answer = []for i in range(4): j = randint(0,9-i) random_answer.append(numbers[j]) numbers.remove(numbers[j]) i = i +1for i in range(4): answer = answer + str(random_answer[i])print(answer)input_number = input('請輸入您猜測的 4 個數:')while times < 8 and input_number != answer: for i in range(4): for j in range(4): if i==j and input_number[i]==answer[j]: count_a = count_a + 1 elif input_number[i]==answer[j]: count_b = count_b + 1 print(str(count_a)+'A'+str(count_b)+'B') count_a=0 count_b=0 times = times + 1 input_number = input('請輸入您猜測的4個數:')if input_number == answer : print('您答對了,正確答案是' + answer)else: print('作答已達8次,遊戲結束,正確答案是 ' + answer)