Mag Rosbit
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Algorithme et programme Ex : 1) Problème : Calcul de la somme des nombres premiers entiers 2) Mise en place de l'algorithme : ``` Algo : somme=0 Pour i allant de 1 à n: somme=somme+i Fin Pour ``` 3) Implémentation de l'algorithme en Python : ```python= somme = 0 for i in range(n): somme += 1 ``` En informatique nous manifestons des variables Une variable se caractérise par: * Un nom * Une valeur * Un type Exemple : toto = 5 ```python= maVariable = 1.58 ``` * "maVariable" représente le nom de la variable ; * 1.58 correspond à sa valeur ; * Cette variable est de type flottant/`float` ```python= monBooleen1 = True monBooleen2 = False ``` * monBooleen1 et monBooleen2 représentent les noms des variables ; * true et false sont des valeurs de ces deux variables ; * monBooleen1 et monBooleen2 sont de type booléens/bool. ```python= a = 15 # variable de type entier/int print(a) # affichage de la variable a b = 1.25 # variable de type float/flottant print(b) # affichage de la variable b c = "JDA" # variable de type chaine de caractères/string print(b) # affichage de la variable c ``` ## Expressions Les expressions sont composées de variables et d'opérateurs. Il existe d 'expression est déterminé par le type d'opérateurs utilisé. Il existe 4 types d'opérateurs principalement : * L'opérateur d'affectation `=` ; * Les opérateurs arithmétiques `+`,`-`,`*`,`/`,`%`,`//`,`**` ; * Les opérateurs logiques` and` `or` `not` `xor`; * Les opérateurs de comparaison `<` `>` `<=` `>=`; ## Schéma ![](https://i.imgur.com/YzFo1IH.png) Les expressions de comparaison produisent des bouléens. Exemple : ```python= a = 45 b=20 # operateur == : tester l'egalite c = a == b print(c) # inegalite non stricte # operateur < : test de comparaison d = a < b e = b < a print(d) print(e) # operateur > : test de comparaison d = a > b e = b > a print(d) print(e) # operateur >= : test de comparaison f = a >= b g = b >= a print(f) print(g) # operateur <= : test de comparaison h = a <= b i = b <= a print(h) print(i) ``` ## Expression de comparaison L'exécution de expression de comparaison aboutit à un booléen. Il est possible de comparer des expressions arithmétiques. ## Opérateurs logiques * and : "et" logique * or : "ou" logique * not : négation * xor : "ou" exclusif ## Table de vérité du "and" logique ![](https://i.imgur.com/cso8r9K.png) Exemple : expression logique True and False ressort False True and True ressort True False and False ressort False a = 15 b = 20 (a == b) and (b <= a) False and False = False ## Schéma de la table de vérité du "ou" logique ![](https://i.imgur.com/kPAG9hA.png) a = 11 b = 25 (a == b) or (a < b) False or True = True a=17 b=37 c=23 test=a!=b print(test) ## Opérateurs sur chaînes de caractères ```python= c = "Salut" b = "ca va ?" d = c + ' ' + b # concaténation print() e = (b+'.') * 4 #répétition d'un chaîne de caractères ``` ![](https://i.imgur.com/OeNXHsx.png) ## Table de vérité du "xor" logique ```python= # exemple a= True b = False print(a^b) ``` ## Conditionnelle ```python= moyg = 13 meg = True if moyg > 12 and moyg < 15 and meg == False : print(encouragements) elif moyg > 15 and meg == False : print(felicitations) else: print('blanc') ``` ## Les boucles ```python= liste=[[1,3,4,2],[1,4,6,2],[2,7,9,1],[1,2,0,0]] for e in liste: sum=0 for i in e: sum=sum+i print ("La somme de",e,"est égale à:" ,sum) ``` ## Les fonctions ```python= def moyenne(liste): # nom et paramètres à prendre en entrée somme = 0 longueur = len(liste) for i in liste: somme+=i # += : somme = somme + i return somme/longueur # variable de retour # simple analyse syntaxique si il n'y a pas appel de fonction, c'est-à-dire remplacement des "inconnus" par des valeurs concrètes # test et exemple notes = [10,18,9,12,13] moyenne = moyenne(notes) # appel de fonction print(moyenne) ``` ## Variables locales et globales Une variable globale peut être appelée dans n'importe quel endroit du script. Tandis que la variable locale possède un cadre dans lequel elle peut être appelée : c'est un scope (ou portée). ```python= notes = [10,18,9,12,13] # variable globale def moyenne(liste): somme = 0 # variable locale longueur = len(liste) # variable locale for i in liste: somme+=i return somme/longueur résultat = moyenne(notes) # variable globale print(notes) # pourra s'afficher dans la console print(résultat) # pourra s'afficher dans la console print(somme) # génère une erreur ``` ```python! def bissextile(annee): if (2024 - annee) % 4 == 0: print("Cette année est bissextile") else: print("EH BAH NN HAHAHAHHAHAHA") return bissextile x = int(input("Entre une année : ")) bissextile = bissextile(x) ``` ```python! def nbre_jours (annee,mois): if (mois == 4) or (mois == 6) or (mois == 9) or (mois == 11): return(30) elif (mois == 1) or (mois== 3) or (mois== 5) or (mois == 7) or (mois == 8) or (mois == 10) or (mois == 12): return(31) elif (mois == 2) : if (annee % 4 == 0 ): return(29) else: return(28) ``` mois=="avril" or mois=="juin" or mois=="septembre" or mois=="novembre" and annee==annee: mois=="janvier" or mois=="mars" or mois=="mai" or mois=="juillet" or mois=="aout"or mois=="août" or mois=="octobre" or mois=="décembre" or mois=="decembre"and annee==annee: a=input("Entre un mois : ") b=int(input("Entre une année : ")) nb_jour_mois(a,b) ```python! def nbre_jours(mois,annee): if mois=="avril" or mois=="juin" or mois=="septembre" or mois=="novembre" and annee==annee: print (30) elif mois=="janvier" or mois=="mars" or mois=="mai" or mois=="juillet" or mois=="aout"or mois=="août" or mois=="octobre" or mois=="décembre" or mois=="decembre": print(31) elif (mois =="fevrier" or "février"): if (annee % 4 == 0): print(29) else: print(28) a=input("Entre un mois : ") b=int(input("Entre une année : ")) nbre_jours(a,b) ``` ```python! n = int(input("met ton chiffre")) for i in range(n,-1,-1): print(i) ``` ```python! def decrementer(n): while n>0 : print(n) n=n-1 ``` ```python! return 5 elif n=="6": return 6 def char_int(nombre_str): lst_digit = list(nombre_str) resultat = 0 for i in range (len(lst_digit)): chiffre = convertir_digit(lst_digit[i]) resultat+= chiffre * 10**(len(lst_digit)-i-1) return résultat & ``` ```python personnes = { "Toto Lemignon" : {"taille" : 153, "pays" : "Espagne", "age":17}, "Titi Lesympa" : {"taille" : 145, "pays" : "France", "age":13} } #Version 1 def age_personne(personnes, nom): if nom in personnes.keys(): return personnes[nom]["age"] else: return None print(age_personne(personnes,"Coucou")) print(personnes.keys()) #Version 2 def age_personne2(personnes, nom): for i in personnes : if i==nom : return personnes [nom]["age"] return None ``` ```python= # exercice 11 def moyenne_tailles(personnes): somme_tailles = 0 nb_personnes = 0 for i in personnes: somme_tailles+= personnes[i]["taille"] nb_personnes+=1 return somme_tailles/nb_personnes print(moyenne_tailles(personnes)) ``` if in : keys() : récupère une liste de clés values() : ON NE PEUT PAS TJR MODIFIER UN DICO SINON IL PEUT Y AVOIR UN CONFLIT PARCE QU'ELLES SONT UNIQUES ```python= def carte_valide(carte): couleurs = ["Pique", "Coeur","Carreau", "Trèfle"] if type(carte[0]) == int and type(carte[1]) == str: if carte[0] > 1 and carte[0] < 15 and carte[1] in couleurs: return True else : return False else : return False print(carte_valide((5,"Pique"))) print(carte_valide((1, "Toto"))) print(carte_valide(("Titi", "Toto"))) ``` ```python= def nom_carte(carte): valeurs = {14 : "AS", 2 : "2", 3 : "3", 4 : "4", 5 : "5", 6: "6", 7 : "7", 9 : "9", 10 : "10", 11 : "Valet", 8 : "8", 12 : "Dame", 13 : "Roi" } return valeurs[carte[0]] +" de "+ carte[1] def nom_carte2(carte): valeurs = {14 : "AS", 11 : "Valet", 12 : "Dame", 13 : "Roi" } if carte[0] >= 2 and carte[0]<= 10: return str(carte[0]) +" de "+ carte[1] else : return valeurs[carte[0]] +" de "+ carte[1] # test print(nom_carte((14,"Pique"))) print(nom_carte2((14,"Pique"))) ``` ```python= def jeux_cartes(): couleurs = ["Pique", "Coeur","Carreau", "Trèfle"] liste_cartes = [] for i in couleurs: for j in range(2,15): liste_cartes.append(nom_carte((j,i))) # autre possibilité : # liste_cartes += [nom_carte((j,i)] return liste_cartes print(jeux_cartes()) ``` ```python= def tirage_aleatoire(): jeu = jeux_cartes() index_carte = randint(1,52) return jeu[index_carte] print(tirage_aleatoire()) ``` ## Complexité algorithmique https://docs.google.com/presentation/d/1-LVSjHned7E61JTQxl_eoiQN0e8A376YRtD26d0ExMM/edit Quadratique = n² ```python= from random import randint def melanger(tab): for x in range(len(tab)): # y=randint(0,(len(tab)-1)) # stockage de la valeur de l'element à supprimer dans une variable intermédiaire n=tab[y] # on retire l'élément d'indice y dans tab tab.pop(y) # on ajoute en dernière position l'élément retiré précédemment tab.append(n) return tab t = [1,2,3,4,5] print(melanger(t)) ``` ```python= def jeux_cartes(): couleurs = ["Pique", "Coeur","Carreau", "Trèfle"] liste_cartes = [] for i in couleurs: for j in range(2,15): y=randint(0,(len()-1)) n=tab[y] tab.pop(y) tab.append(n) return liste_cartes print(jeux_cartes()) ``` ```python= from random import randint def melanger(tab): for x in range(len(tab)): y=randint(0,(len(tab)-1)) n=tab[y] tab.pop(y) tab.append(n) return tab t = [1,2,3,4,5] print(melanger(t)) ``` ```python= def amstrong(p): q = list(str(p)) s = 0 for c in q: s = s + int(c)**3 if s == p: return True else: return False g = amstrong(29932) print(g) ``` :: = partitionnement

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully