python 3.x - How should I fix my infinite while loop that takes in 3 conditions? Also stylistic questions for novice -


Write a code to test the Halston sequence, also called the Bohol Estimate. The code will print the number of iterations of the halestone sequence. End_num = eval (input ("eliminate the number of the range:"))

  def main (): start_num = eval (input (Enter the starting number of the range: ")) end_num = eval / Code>  

The main problem is that my code gives an infinite loop. I want to see all of these conditions in a statement

  while (start_num> 0 more End_num & gt; 0 and end_num & gt; start_num): cycle_length = 0 max_length = 0 max_number = 0   

My code looks disabled, possibly in this category (i_num, (end_num + 1)) In the category I

  contact the problem There is a better way of: cycle_length = 0 while (i! = 1): if (i% 2 == 0): i = i // 2 cycles_long + = 1 if (i% 2 == 1): i = ( (3 * i) + 1) Cycle_length + = 1 print (cycle_length)   

I have just started coding, and I always know that to face these problems, one more Efficient way Any suggestions on methodology, problem solving, or stylistic advice will be greatly appreciated.

Here's an answer in Java. I think we will not start with 1.

  public static zero main (string [] args) {int counter = 0; Scanner sc = new scanner (System.in); System.out.println ("Please give us a number to start:"); Int start = sc.nextInt (); System.out.println ("Give us a number to the end:"); Int end = sc.nextInt (); If (end> starts) {for (int i = 0; i & lt; = end - start; i ++) {counter = 0; Int num = start + i; Int temp = num; While (temporarily! = 1) {if (temp% 2 == 0) {temp = temp / 2; } Else {temp = 3 * temp +1; } Counter ++; } System.out.println (num + "takes" + counter + "iterated."); }} And {System.out.println ("your numbers do not mean"); }}   

There is an answer in Python, if you are trying to solve this problem late. : P is a good night.

  start_num = 1 end_num = 10 for category i (start_num, (end_num + 1)): cycle_length = 0 num = i while (num! = 1): if (num% 2 == 0): num = num // 2 cycle_length + = 1 other: num = ((3 * num) + 1) cycle_lamp + = 1 print (cycle_length)    < / Html>

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -