Avez-vous une question? (216) 97 656 803 hajjriadh@gmail.com
Python

Correction Exercices Fonctions python

Un cours complet pour maîtriser Correction Exercices Fonctions python.

0 chapitres 0 QCM Accès gratuit
  1. Objectifs

    • Connaitre les fonctions de python
    • Etre capable d'écrire des fonctions simples.
  2. Exercice:01

    1. Énoncé
    2. Solution
      # procedure
      def table(mul, bornInf, bornSup):
         
          while bornInf <= bornSup:
              print(bornInf, 'x', mul, '=', bornInf*mul)
              bornInf += 1
      # programme principal -----------------------------
      table( mul=int(input("Saisir le nombre multiplicateur")),
      bornInf=int(input("Saisir le borne Inferieur")),
      bornSup=int(input("Saisir le borne Inferieur")))
  3. Exercice:02

    1. Énoncé
    2. Solution
  4. Exercice:03

    1. Énoncé
    2. Solution
  5. Exercice:04

    1. Énoncé
    2. Solution
  6. Exercice:05

    1. Énoncé
    2. Solution
  7. Exercice:06

    1. Énoncé
    2. Solution
  8. Exercice:09

    1. Énoncé
    2. Solution

        Exercices Fonctions python

  9. Exercice:10

    1. Énoncé
    2. Solution
      def get_name():
          name = input("quel est votre nom ?")
          return name
      def calc_calories(miles, calories_per_mile):
          calories = miles * calories_per_mile
          return calories
      distance = int(input(
          "combien de miles avez-vous fait cette semaine?"))
      burn_rate = 50
      biker = get_name()
      calories_burned = calc_calories(distance,burn_rate)
      print(biker, ", vous avez brûlé à propos"
            ,calories_burned,"calories.")
  10. Exercice:11

    1. Énoncé
    2. Solution
      def NbcMin(passe):
          nb = 0
          for i in passe:
              if 'a' <= i <= 'z':
                  nb += 1
          return nb
       
       
      def NbcMaj(passe):
          nb = 0
          for i in passe:
              if 'A' <= i <= 'Z':
                  nb += 1
          return nb
       
       
      def NbcAlpha(passe):
          return len(passe)-NbcMaj(passe)-NbcMin(passe)
       
       
      def longMaj(passe):
          d = 0
          s = 0
          i = 0
          while i < len(passe):
              if 'A' < passe[i] < 'Z':
                  s += 1
              else:
                  if s > d:
                      d = s
                      s = 0
              i += 1
       
          return d
       
       
      def longMin(passe):
          d = 0
          s = 0
          i = 0
          while i < len(passe):
              if 'a' < passe[i] < 'z':
                  s += 1
              else:
                  if s > d:
                      d = s
                      s = 0
              i += 1
       
          return d
       
       
      def score(password):
          bonus = (len(password)-NbcMin(password))*3+(len(password) -
           NbcMaj(password))*2+((len(password)-NbcAlpha(password))*5)
          penalites = longMaj(password)*3+longMin(password)*2
          val = bonus-penalites
          if val < 20:
              print('Très faible')
          elif val < 40:
              print('Faible')
          elif val < 80:
              print('Fort')
          else:
              print('Très fort')
       
       
      pas = "P@SI_promo2016"
      score(pas)     
      
  11. Exercice:12

    1. Énoncé
    2. Solution
      limiteInf = int(input("Saisir la limite inférieur : "))
      limiteSup = int(input("Saisir la limite supérieur : "))
      
      print("Nombres premiers entre", limiteInf, " et ", limiteSup, " sont :")
      
      for num in range(limiteInf, limiteSup + 1):
         # tous les nombres premiers sont supérieurs à 1
         if num > 1:
             for i in range(2, num):
                 if (num % i) == 0:
                     break
             else:
                 print(num)