machinesous.py

Created by schraf

Created on September 14, 2018

1.14 KB

Sur une machine à sous d’un casino, on gagne 50€ dès que l’on a 3 valeurs identiques (3 Rois, 3 Dames ou 3 Valets) et chaque partie coute 2€. Voici les résultats que d’un joueur :

var casino= ['DVR','VVR','RDV','VVV','RRV','DVD','VRV','RVD','DVD','VRV','VRV','DDD','DDV','VRR','DVV','DDR','RRR','DRR','DRR','DVR','DDD','VVD','DRR','RRD','RRV','RDD','VDV','VDV','VDR','DRV','RVV','VRV','RRD','DRR','DDD','DDV','RVV','VDD','DVR','DRD','VRD','VVV','VRR','DRV','RRV','VVR','DRR','DRV','DDR','VDD','VRD','VVV','RRR','RVR','VVD','RVD','DVD','RVD','VVD','DDR','VVD','RDR','VRD','RDD','VDV','DVR','RVV','RVV','RDV','RRV','RVD','DVD','DDD','RVV','DDR','VDV','VVD','VVD','RVR','VDD','DDD','RDV','RVD','DDR','VDD','RVV','VRV','DRR','RRD','RVV','RVD','VRR','VRV','DRR','DVV','DRV','VRD','VDV','VDV','DRV']

Écrire une fonction gain qui admet en paramètre la liste des résultats obtenus et donne en retour le montant gagné (ou perdu !).

Explications en vidéo


casino= ['DVR','VVR','RDV','VVV','RRV','DVD','VRV','RVD','DVD','VRV','VRV','DDD','DDV','VRR','DVV','DDR','RRR','DRR','DRR','DVR','DDD','VVD','DRR','RRD','RRV','RDD','VDV','VDV','VDR','DRV','RVV','VRV','RRD','DRR','DDD','DDV','RVV','VDD','DVR','DRD','VRD','VVV','VRR','DRV','RRV','VVR','DRR','DRV','DDR','VDD','VRD','VVV','RRR','RVR','VVD','RVD','DVD','RVD','VVD','DDR','VVD','RDR','VRD','RDD','VDV','DVR','RVV','RVV','RDV','RRV','RVD','DVD','DDD','RVV','DDR','VDV','VVD','VVD','RVR','VDD','DDD','RDV','RVD','DDR','VDD','RVV','VRV','DRR','RRD','RVV','RVD','VRR','VRV','DRR','DVV','DRV','VRD','VDV','VDV','DRV']

def gain(parties):
  sortie=0
  for p in parties:
    if p==p[0]*3:
      sortie+=50
    sortie-=2  
  return sortie  

# gain(casino) donnera ici 300

def gain(parties):
  sortie=0
  for p in parties:
    if p=="VVV" or p=="DDD" or p="RRR":
      sortie+=50
    sortie-=2  
  return sortie  

# Version 2

def trois(partie):
  return partie==partie[0]*3

def gainv2(parties):
  return 50*len(list(filter(trois,parties)))-2*len(parties)
  
# Version 3

def gainv3(parties):
  return 50*len([p for p in parties if p==p[0]*3])-2*len(parties)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.