Can someone help me solve this problem? Using python 3.6 to solve it. Please don
ID: 3743667 • Letter: C
Question
Can someone help me solve this problem? Using python 3.6 to solve it. Please don't use function.
2. Specification - Write a program that asks the user for an even number and keeps asking until the user gives an even number. Then tell the user if the number provided is a power of 2 (2,4,8,16,etc.) You cannot use a series of if-statements, you must use arithmetic operations to determine if it is (modulus/divide/multiply/etc) 11 if x==2 or x==4 or x-=8 or #is not allowed 1 Enter an even number 1 2 Must be positive Enter an even number 3 4 Must be even 5 Enter an even number 5 6 Enter an even number 6 The number 6 is not a power of 2Explanation / Answer
while True: num = int(input('Enter an even number: ')) if num % 2 == 0: break elif num < 0: print('Must be positive') else: print('Must be even') temp = num power_of_2 = True while temp > 1: if temp % 2 == 1: power_of_2 = False break temp //= 2 if power_of_2: print('The number %d is a power of 2' % num) else: print('The number %d is not a power of 2' % num)Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.