這次透過 random.randrange(1,9)
來設計個簡單的九九乘法練習
相關的延伸設計與練習,陸續再做補充!
import random
random_num1 = random.randrange(1, 9)
random_num2 = random.randrange(1, 9)
num_ans = random_num1 * random_num2
input_num = input('請輸入' + str(random_num1) + '*' + str(random_num2) + '的答案是多少?:')
try:
input_num = int(input_num)
if num_ans > input_num:
print("答錯囉~答案數字還要再大點喔!")
print("Ans:" + str(num_ans))
elif num_ans < input_num:
print("答錯囉~答案數字比較小喔!")
print("Ans:" + str(num_ans))
elif num_ans == input_num:
print("太厲害了~答對囉!")
print("Ans:" + str(num_ans))
else:
print("不會吧!居然判斷不出來")
except:
print("請輸入正確的正整數!!")
沒有留言:
張貼留言