Question
Using Python 3.6.0 Consider the following code. It is supposed to take a list of numbers from the user. Make a new list containing only
Using Python 3.6.0
Consider the following code. It is supposed to take a list of numbers from the user. Make a new list containing only the numbers which are multiples of 2. Finally it is supposed to print these numbers 5 numbers in a line.
It uses two functions ispow2 which takes a number n and returns the boolean value True if that number is a power of 2 otherwise False.
print5 which takes a list and prints the list 5 numbers per line separated by spaces.
Please write code the correct ispow2 and print5 functions and submit the complete program. Everything in main() is already correct.
def ispow2(n):
def print5(lst):
def main(): lst = input("Please enter the list") nums = [int(j) for j in lst.split()]
newlst = [] for i in nums: if (ispow2(i)): newlst.append(i)
print5(newlst) main()
Sample output:
Please enter the list:2 4 8 5 7 9 2 4 8 2 16 17
2 4 8 2 4
8 2 16
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started