File: pythontex.tex

package info (click to toggle)
auto-multiple-choice 1.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 92,612 kB
  • sloc: perl: 26,752; xml: 24,889; cpp: 1,997; python: 895; makefile: 569; sh: 233; ansic: 195
file content (106 lines) | stat: -rw-r--r-- 2,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
\documentclass[a4paper]{article}

\usepackage[utf8x]{inputenc}    
\usepackage[T1]{fontenc}

\usepackage[francais,bloc,completemulti]{automultiplechoice}    

\usepackage{pythontex}

\begin{pycode}
import random
import math

random.seed(12345)
indices = [0,1,2,3,4]

def nouveau_vecteur():
  random.shuffle(indices)
  while indices[0]==0:
    random.shuffle(indices)
  return random.sample([1,2,3,4,5,6,7,8,9], 5)

def deux_entiers():
  return random.sample([2,3,4,5], 2)  

def myf(x,y) :
  return (2*x+y)*(x-y)

\end{pycode}

%--------
% DOCUMENT
%--------
\begin{document}

\setdefaultgroupmode{withoutreplacement}

\def\AMCdecimalPoint{\raisebox{1ex}{\bf ,}}

\element{questions}{
\begin{question}{fonctionf}
  \pyc{i,j=deux_entiers()}
  On considère la fonction $f$ définie par $f(x,y)=(2x+y)(x-y)$.
  
  Calculer $f(\py{i},\py{j})$
  
  \begin{reponseshoriz}
    \bonne{$\py{myf(i,j)}$}
    \mauvaise{$\py{myf(j,i)}$}
    \mauvaise{$\py{-myf(i,j)}$}
    \mauvaise{$\py{-myf(j,i)}$}
  \end{reponseshoriz}
\end{question}
}

\element{questions}{
\begin{question}{list}
  \pyc{vect=nouveau_vecteur()}
  \pyc{i=indices[0]}
  On considère la liste python \texttt{vect = \py{vect}}.
  Quelle est la valeur de \texttt{vect[\py{i}]} ?
  \begin{reponseshoriz}
    \bonne{\py{vect[i]}}
    \mauvaise{\py{vect[indices[1]]}}
    \mauvaise{\py{vect[indices[2]]}}
    \mauvaise{\py{vect[indices[3]]}}
    \mauvaise{\py{vect[indices[4]]}}
  \end{reponseshoriz}
\end{question}
}

\element{questions}{
\begin{questionmultx}{racine}
  \pyc{x=random.choice([3,5,6,7,8])}
  \pyc{valeur=math.sqrt(x)}
  %
  Prenez votre calculatrice et calculez une valeur approchée de
  $\sqrt{\py{x}}$, en arrondissant soigneusement à deux chiffres après
  la virgule.
  \pys{\AMCnumericChoices{!{valeur}}{digits=3,decimals=2,sign=false,approx=1}}
\end{questionmultx}
}

\exemplaire{5}{    

  \noindent{\bf QCM  \hfill TEST}

  \vspace*{.5cm}
  \begin{minipage}{.4\linewidth}
    \centering\large\bf Devoir surveillé \end{minipage}
  \champnom{\fbox{    
      \begin{minipage}{.5\linewidth}
        Nom et prénom :
        
        \vspace*{.5cm}\dotfill
        \vspace*{1mm}
      \end{minipage}
    }}
  
  \vspace{5ex}
  
  \restituegroupe{questions}

}

\end{document}