Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3949
| Path | csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Dominique <zzz@aol.com> |
| Newsgroups | fr.comp.lang.python |
| Subject | Re: Affichage en notation scientifique. |
| Date | Wed, 14 Sep 2022 17:25:39 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 46 |
| Message-ID | <tfsrpk$30rm6$1@dont-email.me> (permalink) |
| References | <tfsmg1$2vqdl$1@dont-email.me> <87a672xbrj.fsf@universite-de-strasbourg.fr.invalid> <exposant-20220914155942@ram.dialup.fu-berlin.de> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Wed, 14 Sep 2022 15:25:40 -0000 (UTC) |
| Injection-Info | reader01.eternal-september.org; posting-host="8894558db0d5460c4ced3f0ce4a43f4d"; logging-data="3174086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ieRmpM2FxmmRj5Vi63RC6KiVG5INi9Nc=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 |
| Cancel-Lock | sha1:MCMKhYO6NbHe9Bd44IdbFhiEg2A= |
| Content-Language | fr |
| In-Reply-To | <exposant-20220914155942@ram.dialup.fu-berlin.de> |
| Xref | csiph.com fr.comp.lang.python:3949 |
Show key headers only | View raw
Le 14/09/2022 à 17:00, Stefan Ram a écrit :
> Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> writes:
>> 1) pour formater un flottant en notation scientifique :
>> "%e" % (123456.0) # ou "{:e}".format (123456.0)
>> vec des tas de variantes (cf.
>> https://docs.python.org/3/library/string.html#formatspec)
>
> Dans l'énoncé du problème, une variante précise était en
> effet indiquée : 1.236354e6. Je ne l'obtiens ici qu'avec
> "replace".
>
> f"{chiffre:e}".replace( "e+0", "e" ).replace( "e-0", "e-" )
>
>> 2) Pour extraire mantisse est exposant, il y a math.frexp, mais
>
> On pourrait aussi utiliser des chaînes de caractères pour la
> séparation.
>
> def separez( chiffre ):
> notation = f"{chiffre:.6e}"\
> .replace( "e+0", "e" )\
> .replace( "e-0", "e-" )
> pos = notation.find( 'e' )
> return notation[ :pos ], notation[ pos+1: ]
>
> ( mantisse, exposant )= separez( 1236354 )
>
> print( mantisse, exposant )
>
>
Bonsoir,
J'ai trouvé cette solution :
from math import log10
test=int(input('Nombre '))
exp=int(log10(test))
print(exp)
Pour résoudre certains exercices du livre, c'est de cet exposant dont
j'ai besoin.
Je vous remercie pour votre aide,
Dominique
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 15:55 +0200
Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 16:17 +0200
Re: Affichage en notation scientifique. Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-09-14 16:37 +0200
Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 17:25 +0200
Re: Affichage en notation scientifique. Dominique <zzz@aol.com> - 2022-09-14 18:33 +0200
Re: Affichage en notation scientifique. Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-09-14 18:59 +0200
csiph-web