IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Erreur programmation python.


Sujet :

Python

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Informatique et système
    Inscrit en
    Janvier 2015
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informatique et système

    Informations forums :
    Inscription : Janvier 2015
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Erreur programmation python.
    Bonjour,

    Je suis un utilisateur python qui souhaiterais résoudre quelques erreurs concernant mon scripte.

    Il s'agit d'un programme qui convertit les valeurs en binaire-octale-decimale-hexadecimale.

    Il y a toujours un problème de boucle et le scripte s'arrête toujours au moment de donner le résultat.

    J'aimerais connaitre la ligne script qui pose problème.

    Un tout grand merci d'avance.





    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    #-*-coding in UTF-8!*-
     
    #Fonction qui eleve a plusieurs puissances
    import os
    def bin2dec(nombre):
    	decimal = 0
    	for i in range(len(nombre)-1,-1,-1):
    		 if nombre[i]=="1":
    			 decimal = decimal + int(nombre[i])*2**(len(nombre)-i-1)
    	print (decimal)
     
    def oct2dec(nombre):
    	decimal = 0
    	for i in range(len(nombre)-1,-1,-1):
    		decimal = decimal + int(nombre[i])*8**(len(nombre)-i-1)
     
    	return(decimal)
     
    def dec2dec(nombre):
    	decimal = 0
    	for i in range(len(nombre)-1,-1,-1):
    		decimal = decimal + int(nombre[i])*10**(len(nombre)-i-1)
     
    	return(decimal)
     
    def hex2dec(nombre):
    	decimal = 0
    	for i in range(len(nombre)-1,-1,-1):
    		decimal = decimal + int(nombre[i])*16**(len(nombre)-i-1)
     
    	return(decimal)
     
    choix=""
    choixtrans=""
    while choix!="1" and choix!="2" and choix!="3" and choix!="4":
    	if choix!="" and choix!="1" and choix!="2" and choix!="3" and choix!="4":
    		print ("erreur, vous navez pas rentre une bonne commande.")
    	print ("Selectionner sous quelle base la variable va etre entre.")
    	print ("1.binaire(2)")
    	print ("2.octal(8)")
    	print ("3.decimale(10)")
    	print ("4.hexadecimal(16)")
    	choix=input()
     
    print ("Entrez une valeur en respectant la base selectioner.")
    some=input()
     
    while choixtrans!=1 and choixtrans!=2 and choixtrans!=3 and choixtrans!=4 and choixtrans!=5:
    	if choixtrans!="" and choixtrans!=1 and choixtrans!=2 and choixtrans!=3 and choixtrans!=4:
    		print ("erreur, vous navez pas rentre une bonne commande.")
    	else : 
    		print ("En quel base voulez-vous transformer?")
    		print ("1.binaire(2)")
    		print ("2.octal(8)")
    		print ("3.decimale(10)")
    		print ("4.hexadecimal(16)")
    	choixtrans=int(input())
     
    if choix=="1":
    	if choixtrans=="2":
    		data=bin2dec(bin)
    	elif choixtrans=="3":
    		data=bin2dec(bin)
    	elif choixtrans=="4":
    		data=bin2dec(bin)
    	elif choixtrans=="5":
    		data=""
    elif choix=="2":
    	if choixtrans=="1":
    		data=""
    	elif choixtrans=="3":
    		data=""
    	elif choixtrans=="4":
    		data=""
    	elif choixtrans=="5":
    		data=""
    elif choix=="3":
    	if choixtrans=="1":
    		data=""
    	elif choixtrans=="2":
    		data=""
    	elif choixtrans=="4":
    		data=""
    	elif choixtrans=="5":
    		data=""
    elif choix=="4":
    	if choixtrans=="1":
    		data=dec2bin(dec)
    	elif choixtrans=="2":
    		data=dec6hex(dec)
    	elif choixtrans=="3":
    		data=dec8oct(dec)
    	elif choixtrans=="5":
    		data=dec16hexd(dec)
    elif choix=="5":
    	if choixtrans=="1":
    		data=""
    	elif choixtrans=="2":
    		data=""
    	elif choixtrans=="3":
    		data=""
    	elif choixtrans=="4":
    		data=""
    print ("le nombre vaut",data)
     
     
     
    print ("erreur, vous navez pas rentre une bonne commande")
    print ("voulez-vous quiter le programme?")
    print ("1.OUI")
    print ("2.NON")
    sortie=input()
     
    from math import*

  2. #2
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2011
    Messages : 180
    Points : 321
    Points
    321
    Par défaut
    Bonjour

    En Python, l'indentation est significative.
    Donc, veuillez éditer votre post de façon à inclure le votre dans la balise ad-hoc (le bouton marqué d'un #)


  3. #3
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 776
    Points
    36 776
    Par défaut
    Salut,

    Maintenant que j'ai édité le message pour qu'on puisse lire le code, je peux mettre à jour le post de chticricri:
    Citation Envoyé par chticricri Voir le message
    Bonjour

    En Python, l'indentation est significative.
    Donc, veuillez éditer votre post de façon à inclure le votre dans la balise ad-hoc (le bouton marqué d'un #)
    C'est une bonne piste pour résoudre votre problème de boucle

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. Réponses: 145
    Dernier message: 15/02/2009, 11h51
  2. Erreur Programmes!!! (ebesoin d'aide)
    Par charfamine dans le forum MFC
    Réponses: 6
    Dernier message: 08/04/2006, 13h16
  3. [MySQL] Erreur programme
    Par Didier100 dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 14/01/2006, 22h12
  4. [Lien]erreur dans mon programme python
    Par durnambule dans le forum Général Python
    Réponses: 11
    Dernier message: 29/01/2004, 14h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo