In python please: Write a while loop that prints user_num divided by 2 until use
ID: 3595992 • Letter: I
Question
In python please: Write a while loop that prints user_num divided by 2 until user_num is less than 1. Sample output for the given program: 10.0 5.0 2.5 1.25 0.625 Write a while loop that prints user.num divided by 2 until us 10.0 5.8 2.5 1.25 0.625 Note: These activities may test code with different test value user-num = 1, then with user-num = 0, then with user-num = Also note: If the submitted code has an infinite loop, the syste Program end never reached The system doesn't print the te 1, user-num = 2e 3 Your solution goes here" 4.Explanation / Answer
Below is the program for printing the number less than 1 based on input, below is the explanation
#!/usr/bin/python // directory
user_num = 10.0 // here we are initilaizing the user-num as 10.0 as we know that in python the //data type was based on the assigned number.
print user_num
while user_num >= 1 : // here we are checking the condition whether the number is lees than or equals // to 1 if the condition is satisfies then usernum is calculated and printing the user_num
user_num = user_num / 2 // here we are performing the division operation and storing the value in same //user_num
print user_num // here we are performing the printing of the number
Program
#!/usr/bin/python
user_num = 10.0
print user_num
while user_num >= 1 :
user_num = user_num / 2
print user_num
Output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.