Deutsch   English   Français   Italiano  
<tfsrpk$30rm6$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!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>
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>
Bytes: 2477

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