Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my program so far. I keep getting an error at, if num >=0. i need to use while at the start of the program. please

image text in transcribed
my program so far. I keep getting an error at, if num >=0. i need to use while at the start of the program.
image text in transcribed
please help me correct it. Thank you.
Problem 4 Write a program that reads a positive integer value, and compute the following sequence: If the value is even, halve it. If it's odd, multiply by 3 and add 1. Repeat this process until the value is 1, printing out each value. . Finally print out how many of these operations you performed. . Note: If the input value is less than 1, print a message containing the word Error and exit the program. This is how the output should look like: Initial value is: 9 Next value is: 28 Next value is: 14 Next value is: 7 Next value is: 22 Next value is: 11 Next Value 18: 34 1 1 2 while True: 3 num = = -1 4 num = = float(input("Enter a positive number") 5 if num >= 0 : 6 break 7 else: 8 print("Error") 9 if(num 2) == 0: 10 print("next value is", (num//2)) 11 else: 12 print("next value is", (num * 3 + 1))L 13 . W No WNHO 00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. Competence management.

Answered: 1 week ago

Question

Recognize the four core purposes service environments fulfill.

Answered: 1 week ago