gabu.py

Created by pascal-chauvin

Created on December 21, 2018

898 Bytes

Un nombre entier est augmenté d’une unité à chaque tour : le programme demande si le nombre est divisible par 3, par 5, ou les deux, jusqu’à atteindre 100 ou la première erreur.


#!/usr/bin/env python3

# fichier: gabu.py
#  auteur: Pascal Chauvin
#    date: 2018/12/21

fini = False
perdu = False

n = 0

while not fini:
  print("*** nombre {} ***".format(n))
  print("- multiple de 3, taper 1")
  print("- multiple de 5, taper 2")
  print("- multiple de 3 et de 5, taper 3")
  print("- aucun, taper 0")

  choix = int(input("votre choix ? "))
  
  perdu = True

  if choix == 1:
    if (n % 3) == 0:
      if (n % 5) != 0:
        perdu = False

  if choix == 2:
    if (n % 5) == 0:
      if (n % 3) != 0:
        perdu = False

  if choix == 3:
    if (n % 3) == 0:
      if (n % 5) == 0:
        perdu = False

  if choix == 0:
    perdu = False
    if (n % 3) == 0:
      perdu = True
    if (n % 5) == 0:
      perdu = True

  if perdu == True:
    fini = True

  if fini == False:
    n += 1

  if n >= 100:
    fini = True

print("score : {} %".format(n))

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.