最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

24點解題和出題工具

2023-07-12 15:36 作者:開朗的小盆友yyds  | 我要投稿

接著上一篇文章

24點解題工具代碼:

import itertools

#by jason

def calculate24(nums):

? ? permutations = list(itertools.permutations(nums))

? ? operators = list(itertools.product(["+", "-", "*", "/"], repeat=3))

? ? for perm in permutations:

? ? ? ? for operator in operators:

? ? ? ? ? ? equation = f"{perm[0]} {operator[0]} {perm[1]} {operator[1]} {perm[2]} {operator[2]} {perm[3]}"

? ? ? ? ? ? if abs(eval(equation) - 24) < 1e-6:

? ? ? ? ? ? ? ? return equation.replace("//", "/")

? ? return "無解"

while 1:

????a=int(input("1:"))

????b=int(input("2:"))

????c=int(input("3:"))

????d=int(input("4:"))

????print(calculate24([a, b, c, d]))

????input("_____________________________________")






24點出題工具代碼:

#by jason

import itertools

import random as r


def py24(nums):

? ? permutations = list(itertools.permutations(nums))

? ? operators = list(itertools.product(["+", "-", "*", "/"], repeat=3))

? ? for perm in permutations:

? ? ? ? for operator in operators:

? ? ? ? ? ? equation = f"{perm[0]} {operator[0]} {perm[1]} {operator[1]} {perm[2]} {operator[2]} {perm[3]}"

? ? ? ? ? ? if abs(eval(equation) - 24) < 1e-6:

? ? ? ? ? ? ? ? return equation.replace("//", "/")

? ? return "No"

while 1:

? ? a=r.randint(1,10)

? ? b=r.randint(1,10)

? ? c=r.randint(1,10)

? ? d=r.randint(1,10)

? ? f=[a,b,c,d]

? ? if((py24(f))!="No"):

? ? ? ? print(a," ",b," ",c," ",d,' ')

? ? ? ? input("")

? ? ? ? print(py24(f))

? ? ? ? input("")

? ? ? ? print("___________________________________________________________________")


? ? else:

? ? ? ? pass





24點解題和出題工具的評論 (共 條)

分享到微博請遵守國家法律
财经| 云林县| 建瓯市| 繁峙县| 洪湖市| 汾阳市| 杨浦区| 扎赉特旗| 汶上县| 泰和县| 视频| 建昌县| 临邑县| 拉萨市| 岫岩| 盐源县| 沈丘县| 垫江县| 谢通门县| 鸡东县| 墨脱县| 平顺县| 邯郸县| 塘沽区| 旅游| 双鸭山市| 阿克| 射阳县| 洛浦县| 邮箱| 隆尧县| 铜梁县| 康马县| 澎湖县| 孟津县| 苍梧县| 抚州市| 特克斯县| 平远县| 长沙市| 错那县|