I have to create a program that asks the user for natural numbers or 0
to finish and for each number that the user enters, the program must create a juggling sequence and display them on the screen.
In turn, when the program ends, you must show on the screen which was the number that generated the longest and shortest succession.
This is what the succession does:
if number is even = > number = number ^ (1/2)
if number is odd = > number = number ^ (3/2)
And the sequence ends when number = 1
Here the code:
numero = int(input('Ingrese un numero natural o 0 para terminar: '))
contador_max = 0
contador_min = 1
while numero != 0:
num = numero
contador = 0
while num != 1:
if num % 2 == 0 :
num = int(num ** 0.5)
print (num,end=' ')
else :
num =int(num ** 1.5)
print(num,end=' ')
contador =+ 1
if contador > contador_max:
contador_max = contador
maximo = numero
if contador < contador_min:
contador_min = contador
minimo = numero
print()
numero = int(input('Ingrese un numero natural o 0 para terminar: '))
print('La sucesion mas larga se genero con el numero:',maximo)
print('La sucesion mas corta se genero con el numero:',minimo)
All this I must do only using While, if, elif, else
and some other that appear there in the code.
As you can see, my problem occurs when I finish the program, since it tells me that the variable minimo
is not defined, and before that error, the other was that, when I said which number I generated the longest and the shorter sequence, I showed the same number for both (the maximum).