# Où est l'erreur en python 3.2 ?

**URL:** <https://www.debian-fr.org/t/ou-est-lerreur-en-python-3-2/67938>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 10:12 UTC](https://www.debian-fr.org/t/ou-est-lerreur-en-python-3-2/67938 "2016-02-21T22:12:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Papy\_Octet](https://www.debian-fr.org/user_avatar/www.debian-fr.org/papy_octet/32/8503_2.png) [@Papy\_Octet](https://www.debian-fr.org/u/Papy_Octet)\
**Post date:** [Février 21, 2016, 10:12 UTC](https://www.debian-fr.org/t/ou-est-lerreur-en-python-3-2/67938/1 "2016-02-21T22:12:50Z")

</div>

Bonjour,

J’ai un petit code en Python 3.2 tout simple qui m’affiche une erreur :

```auto
#!/usr/bin/python3.2
# -*- coding: Utf-8 -*-

import random as rand
import math

def de6(n):
    tirs = [0, 0, 0, 0, 0, 0]
    for i in range(n):
        t = rand.randint(1,6)
        tirs[t-1] += 1
    for j in range(6):
        tirs[j] = tirs[j]*100.0/n
        tirs[j] = {:.2f}.format(tirs[j]) + '%' # 2 nombres après la virgule
        return tirs

```

le message d’erreur est :

> [@](#):
>
> python3.2 -c «&nbsp;import py\_compile; py\_compile.compile(‹&nbsp;Math\_Python.py&nbsp;›)&nbsp;» (dans le dossier : …  
> File «&nbsp;Math\_Python.py&nbsp;», line 14  
> tirs[j] = {:.2f}.format(tirs[j]) + ‹&nbsp;%&nbsp;› # 2 nombres après la virgule  
> …^  
> SyntaxError: invalid syntax  
> Compilation terminée avec succès.

Mais où est donc l’erreur ?

Merci.

---

<div class="post-metadata">

**Author:** ![Dunatotatos](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@Dunatotatos](https://www.debian-fr.org/u/Dunatotatos)\
**Post date:** [Février 21, 2016, 10:12 UTC](https://www.debian-fr.org/t/ou-est-lerreur-en-python-3-2/67938/2 "2016-02-21T22:12:51Z")

</div>

Le format qui t’intéresse est une méthode de string :

`>>> "{:.2f}".format(5.26554)                                                   
'5.27'`

---

<div class="post-metadata">

**Author:** ![Papy\_Octet](https://www.debian-fr.org/user_avatar/www.debian-fr.org/papy_octet/32/8503_2.png) [@Papy\_Octet](https://www.debian-fr.org/u/Papy_Octet)\
**Post date:** [Février 21, 2016, 10:12 UTC](https://www.debian-fr.org/t/ou-est-lerreur-en-python-3-2/67938/3 "2016-02-21T22:12:52Z")

</div>

Merci Dunatotatos.
