62.0k views
2 votes
Code in Python

Write a while loop that prints user_num divided by 2 until user_num is less than 1. The value of user_num changes inside of the loop.

Sample output with input: 20
10.0
5.0
2.5
1.25
0.625


Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message.

My code, it only passes one test with correct outputs
what am I forgetting?

Code in Python Write a while loop that prints user_num divided by 2 until user_num-example-1
User Darune
by
5.1k points

1 Answer

2 votes

You're setting the value of user_num to 20. Doing this won't allow the other test cases to run. Simply delete that line and your code should work. This is the code I wrote:

user_num = int(input())

while user_num>=1:

user_num/=2

print(user_num)

I wrote my code in python 3.8. I hope this helps.

User Bazza
by
4.7k points