PYTHON.2 INFO FEUILLE n° 29 D'EXERCICES BTS1 février 2013
Thème:
Réaliser des QCM
---------------------------------------------------------------------------------------------------------------
EXERCICE 1
Réaliser un QCM qui demande si ln est dérivable sur l'intervalle ] 0 , + ∞ [
et si ln ': x → 1 / x en indiquant finalement si la réponse est bonne.
----------------------------------------------------------------------------------------------------------------
REPONSE:
On peut considérer:
from Tkinter import*
from random import*
def rep1():
       print " bon"
def rep2():
       print "mauvais"
def qcm():
       cadre=Tk() 
       texte=Label(cadre, text=' QCM: ln est dérivable sur ]0,+ ∞ [ ', fg = 'black', bg='white')
       texte.grid(row = 0, column = 1, sticky = W)
       texte=Label(cadre, text=" ln': x → 1/x ", fg = 'black', bg='white')
       texte.grid(row = 6, column = 1, sticky = W)
       bouton= Button( cadre, text='  OUI  ', command=rep1)
       bouton.grid(row = 2, column = 3, sticky = E)
       bouton= Button( cadre, text='NON', command=rep2)
       bouton.grid(row = 4, column = 3, sticky = E)
       bouton= Button( cadre, text='  OUI  ', command=rep1)
       bouton.grid(row = 8, column = 3, sticky = E)
       bouton= Button( cadre, text='NON', command=rep2)
       bouton.grid(row = 10, column = 3, sticky = E)
       cadre.mainloop()
On obtient quand on lance qcm()
La fenêtre suivante:
On peut cliquer dans l'ordre que l'on veut:
Quand on clique ici sur OUI on obtient chaque fois :
bon
Quand on clique sur NON on obtient chaque fois :
mauvais
------------------------------------------------------------------------------------------------------------
EXERCICE 2
Créer un QCM de votre choix.
----------------------------------------------------------------------------------------------------------
REPONSE:
Voici un QCM de trois questions:
from Tkinter import*
from random import*
def rep1():
       print " bon"
def rep2():
       print "mauvais"
def qcm():
       cadre=Tk() 
       texte=Label(cadre, text=' QCM: ln est dérivable sur ]0,+ ∞ [ ', fg = 'black', bg='white')
       texte.grid(row = 0, column = 1, sticky = W)
       texte=Label(cadre, text=" ln': x → 1/x ", fg = 'black', bg='white')
       texte.grid(row = 6, column = 1, sticky = W)
       bouton= Button( cadre, text=' OUI ', command=rep1)
       bouton.grid(row = 2, column = 3, sticky = E)
       bouton= Button( cadre, text='NON', command=rep2)
       bouton.grid(row = 4, column = 3, sticky = E)
       bouton= Button( cadre, text=' OUI ', command=rep1)
       bouton.grid(row = 8, column = 3, sticky = E)
       bouton= Button( cadre, text='NON', command=rep2)
       bouton.grid(row = 10, column = 3, sticky = E)
       texte=Label(cadre, text=' ln est décroissante sur ]0,+ ∞ [ ', fg = 'black', bg='white')
       texte.grid(row = 12, column = 1, sticky = W)
       bouton= Button( cadre, text=' OUI ',command=rep2)
       bouton.grid(row = 14, column = 3, sticky = E)
       bouton= Button( cadre, text='NON', command=rep1)
       bouton.grid(row = 16, column = 3, sticky = E)
       cadre.mainloop()
On obtient la fenêtre:
Les deux premiers OUI sont " bon"
mais le dernier OUI est" mauvais".
-----------------------------------------------------------------------------------------------
EXERCICE
Créer une machine à voter .
-----------------------------------------------------------------------------------------------------
REPONSE:
On peut considérer:
from Tkinter import*
from random import*
def rep1():
       print ""
       print " Félicitation. Une voix de plus pour Rominet"
       print " Rominet est élu."
       print " Merci pour votre spontanéité. "
def rep2():
       print " Désolé,vous vous êtes trompé de bouton."
       print " Ce n'est pas grave."
       print " Vous pouvez recommencer."
 
def vote():
      cadre=Tk()
      texte=Label(cadre, text="Il y a déjà 12 votes pour Rominet sur 24 électeurs.", fg = 'black', bg='white')
      texte.grid(row = 0, column = 1, sticky = W)
      texte=Label(cadre, text="Votez pour l'un des candidats.", fg = 'black', bg='white')
      texte.grid(row = 2, column = 1, sticky = W)
      bouton= Button( cadre, text=' Rominet ', command=rep1)
      bouton.grid(row = 4, column = 3, sticky = E)
      bouton= Button( cadre, text='  Titi  ', command=rep2)
      bouton.grid(row = 6, column = 3, sticky = E)
      cadre.mainloop()
Mais qui va donc être élu?
-------------------------------------------------------------------------------------------------------------------

