生成在线测验题
使用新的内置功能很容易创建和部署表单. 这种表单可以在云中进行部署,通过动态文件、应用程序接口(API)、应用程序等,提供代码和数据的无缝和持久的存储,云计算和即时外部部署. 这些特性在这里通过创建和部署两个“小测验”给以演示. 两个“小测验”分别请求用户来识别身份的某些大城市和某些流行电影.
在云端创建关于美国大城市的测验题.
In[1]:=
CloudDeploy[
FormFunction[{"city",
"How many of the 10 most populous US cities can you name?"} ->
RepeatingElement[
Restricted[
"City", {"Country" -> Entity["Country", "UnitedStates"],
"Population" -> TakeLargest[10]}], {1, {1, 10}}],
GeoListPlot[{#city,
Complement[
EntityList@
Entity["City", {"Country" -> Entity["Country", "UnitedStates"],
"Population" -> TakeLargest[10]}], #city]},
GeoLabels -> True, PlotLegends -> {"OK", "Missed"}] &, "PNG"]]
访问表单并与其互动.
如果任何一个选项不在美国最大的 10 个城市中,表单会显示错误信息.
在云端创建关于电影的测验题.
In[2]:=
CloudDeploy[
FormFunction[{"movies",
"How many of the 10 top grossing movies by Steven Spielberg can \
you name?"} ->
RepeatingElement[
Restricted[
"Movie", {"Director" ->
Entity["Person", "StevenSpielberg::76z25"],
"DomesticBoxOfficeGross" -> TakeLargest[10]}], {1, {1, 10}}],
With[{images =
EntityValue[
EntityClass[
"Movie", {"Director" ->
Entity["Person", "StevenSpielberg::76z25"],
"DomesticBoxOfficeGross" -> TakeLargest[10]}], "Image",
"EntityAssociation"]},
Grid[{
{"you guessed", Length[#movies],
ImageCollage[Values[KeyTake[images, #movies]]]}, {"you missed",
10 - Length[#movies],
ImageCollage[Values[KeyDrop[images, #movies]]]}
}, Frame -> All, Alignment -> Left]] &]]
访问该网页来尝试测验.