Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sans fonction :
- #Functions
- #Main program
- n = int(input("Entrez un nombre : "))
- compt = 0
- while not n==1:
- if n > 0:
- if n % 2 == 0:
- n = n//2
- compt += 1
- print(n)
- else:
- n = n*3+1
- compt += 1
- print(n)
- else:
- print("Erreur le nombre entré est incorrecte")
- print("Il y a eu", compt, "occurences")
- Avec fonction :
- #Functions
- def resol(n):
- compt = 0
- while not n==1:
- if n > 0:
- if n % 2 == 0:
- n = n//2
- compt += 1
- print(n)
- else:
- n = n*3+1
- compt += 1
- print(n)
- else:
- print("Erreur le nombre entré est incorrecte")
- return(compt)
- #Main program
- n = int(input("Entrez un nombre : "))
- compt = resol(n)
- print("Il y a eu", compt, "occurences")
Add Comment
Please, Sign In to add comment