Question

USING PYTHON!! Given an even number x, we keep dividing it by 2 until it becomes...

USING PYTHON!!

Given an even number x, we keep dividing it by 2 until it becomes an odd number, and then print out the last even number. For example, if x = 12, 12/2 = 6, and 6/2 = 3.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

x=int(input("Enter number: "))

while(True):

#maintain the previous even number

#so when we found x as odd than we can return the last even number

if(x%2==0):

y=x

x=x//2

if x%2==1:

break;

print(y)

https://SlategrayAwfulExecutables.udaykumar2.repl.run 1 WN Python 3.7.4 (default, Jul 9 2019, 00:06:43), [GCC 6.3.0 20170516]

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
USING PYTHON!! Given an even number x, we keep dividing it by 2 until it becomes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...

    I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • In Python, we may simplify nested "IF" statements. Given the code: if x <100: if x...

    In Python, we may simplify nested "IF" statements. Given the code: if x <100: if x % 2 == 0: print("x is a two-digit postive even number") which one in the following is a correct simplification for the above nested "IF" statement a.if x <100 or x%2 == 0: print("x is a two-digit postive even number") b.if x <100 and x%2 == 0: print("x is a two-digit postive even number")    c.if x <100 xor x%2 == 0: print("x is...

  • In python using list comprehension, given a list of number, return the list with all even...

    In python using list comprehension, given a list of number, return the list with all even numbers doubled, and all odd numbers turned negative. [72, 26, 79, 70, 20, 68, 43, -71, 71, -2] -> [144, 52, -79, 140, 40, 136, -43, 71, -71, -4]

  • IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we...

    IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we do the following: If the integer is odd, we multiply by 3 and add 1. If the integer is even, we divide by 2. It is hypothesized that the above sequence will always converge to the value of 1, regardless of any valid initial choice. This hypothesis is known as the Collatz Conjecture. For example, if we start at 5, the numbers generated by...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • I need to code that statement in python. The Bold is code we were given and...

    I need to code that statement in python. The Bold is code we were given and the italics are the statements we need to code. oa- ← > C q p t crant ps bb er nauedubbc vebda pid 26210 4-dtcc entid 57221440 1 co ses 1177 NAU00-ISM 320-SECOC2-3961 NAL PSSS Li u Lat6F17see2%281%29 df ::: Apcs welcome Spencer- NFLPl2ers b Cole 訂: YouTube Red-3:es gr Rac-12com Feeds ma Oreon2018 Basce ma Oreocn20'8 Footb2 1 Gobal Gamo wth Cther toocmais...

  • Both questions #1(1-6) and #2 Question t. A die was rolled twice. The first time it landed on a number that we will call “x". The second time it landed on a number that we will call "y&#34...

    Both questions #1(1-6) and #2 Question t. A die was rolled twice. The first time it landed on a number that we will call “x". The second time it landed on a number that we will call "y" We will symbolize some events as follows: x is odd. B x is a prime. γ¡s odd. A: : D: y is a prime. that x andy are both odd may be expressed as P(АЛ C). (1) The chance that x is...

  • Python Help Create a program that outputs a table from 1 to 5 using what you've...

    Python Help Create a program that outputs a table from 1 to 5 using what you've learned about "for" loops. Your program will print the number and indicate if the number is odd or even. If it is not odd you will multiply 2 numbers with it: number 1 and number 2. Your program must do the multiplication for only even numbers in the table. The output of your program should look like the figure below. Hint: Create a program...

  • IN PYTHON. We have seen examples of using the python re library. In this practice, you...

    IN PYTHON. We have seen examples of using the python re library. In this practice, you need to write python code and complete following tasks. (You can decide whether you want to define functions and how to organize your code. It is for your own practice.) 1). Define 10 string variables that follows the requirement given an integer, a float, a double, a float end with letter f (4.321f), Capital Letters( followed by small case letters, followed by digits, Exactly...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT