我目前正在创建一个数学游戏,涉及:加,减,乘和除。这些带有紫色边框的零件是用户在选择添加时为附加零件创建的问题。
我不知道如何随机显示这些问题。当用户每次都选择添加题时,或者每次做完后又回去做一次时,我都希望问题每次都不相同时我希望它们不一样。因此每次都是随机的。
#addition questions
def beginnerquestionsaddition():
os.system('clear')
score = 0
beginner1 = input("2 + 3 = ")
if beginner1 == ("5"):
print("Correct, Well Done!")
score += 1
time.sleep(1)
else:
print("Sorry you got it wrong :(")
time.sleep(1)
os.system('clear')
beginner2 = input("6 + 7 = ")
if beginner2 == ("13"):
print("Correct, Well Done!")
score += 1
time.sleep(1)
else:
print("Sorry you got it wrong :(")
time.sleep(1)
os.system('clear')
beginner3 = input("2 + 5 = ")
if beginner3 == ("7"):
print("Correct, Well Done!")
score += 1
os.system('clear')
time.sleep(1)
endquestadditionbeginner()
print("your score was: ")
print(score)
time.sleep(3)
introduction()
else:
print("Sorry you got it wrong :(")
time.sleep(1)
os.system('clear')
endquestadditionbeginner()
print("your score was: ")
print(score)
time.sleep(3)
introduction()
答案 0 :(得分:0)
因此,这并不是您决定采用该程序的特定方式的确切答案,但这是一种简单得多的方式:
foreach ($ranges2 as $range) {
$range['start'] = DateTime::createFromFormat('Y-m-d', $range['start']);
$range['end'] = DateTime::createFromFormat('Y-m-d', $range['end']);
while ($range['start'] <= $range['end']) {
$date = $range['start']->format('Y-m-d');
$dates[$date] = (isset($dates[$date]) ? $dates[$date] : 0) + 1; 1;//define new $dates array
$range['start']->modify('+1 day');
}
}
当然,这只是示例代码。您可以轻松地纳入积分系统,并且当积分达到一定水平时,难度可能会上升。您也可以将操作随机化。抱歉,如果这不是您想要的,但是我看到了您的代码,我发现简化您的代码没有错...