Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3949

Re: Affichage en notation scientifique.

From Dominique <zzz@aol.com>
Newsgroups fr.comp.lang.python
Subject Re: Affichage en notation scientifique.
Date 2022-09-14 17:25 +0200
Organization A noiseless patient Spider
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>

Show all headers | 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 | NextPrevious in thread | Next in thread | Find similar


Thread

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