Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def verif(ch):
- test=True
- i=0
- while test==True and i!=len(ch):
- if not(ch[i].upper() in ["A","B","C","D","E","F"] or "0"<=ch[i].upper()<="9"):
- test=False
- i=i+1
- return test==True
- def saisie():
- while True:
- ch=input("ch:")
- if len(ch)>0 and verif(ch): break
- return ch
- def convertir(ch):
- s=0
- if ch=="A":
- s=10
- elif ch=="B":
- s=11
- elif ch=="C":
- s=12
- elif ch=="D":
- s=13
- elif ch=="E":
- s=14
- elif ch=="F":
- s=15
- else:
- s=int(ch)
- return s
- def calcul(ch):
- p=0
- x=0
- bi=16**(len(ch)-1)
- for i in range(len(ch)):
- x=bi*convertir(ch[i])
- p=x+p
- bi=bi//16
- return p
- ch=saisie()
- print("n=",calcul(ch))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement