Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program that inputs a string representing a binary number (Os and

ID: 3686765 • Letter: W

Question

Write a Python program that inputs a string representing a binary number (Os and Is). First, your program should verify that it is indeed a binary number. That is. the program should verify that the number contains only Os and Is. If that is not that case, your program should print a message that the number is not a valid binary number. Otherwise, your program should count how many Is are in that string and output that count. Write a Python function named "reverse" that takes a positive integer value as a parameter and returns (not prints) the number with its digits reversed. For example, given the number 7631. the function should return 1367. Incorporate the function into an application that reads a value from the user and displays the result. Write a Python program that reads three lists of positive integers into three separate lists and creates a fourth list that is the intersection of the three lists. The intersection is defined as those values that appear in all three lists. For instance, if the three lists were: |9, 2. 3.4J. |4. 3. 6. 5J and |3, 2, 1. 4). the intersection would be the set (3. 4) because the values 3 and 4 appear in all three lists. If there arc no values in common, this is called an "empty" intersection. Request the values in each list by prompting the user to enter positive integers and to signal the end of input by typing a zero. You may assume that the user will enter the same number of values for each list. Then, calculate the intersection and. if the intersection is non-empty, print the intersection. If the intersection is empty, print an appropriate message.

Explanation / Answer

42) Program to count number of 1's in binary number

Python code:

input_string = raw_input("Please enter a binary number: ")
def is_binary(x):
return set(input_string) <= set('01')
x = is_binary(input_string)
if x == True :
def bitcount(input_string):
count = 0
count = input_string.count('1')
print count
bitcount(input_string)
elif x == False:
print "Enter valid binary number"

43) Program to reverse aa number

Python program

Number = int(raw_input("Please Enter any Number: "))
def reverse(Number):
Reverse = 0
Reminder = 0
while(Number > 0):
Reminder = Number %10
Reverse = (Reverse *10) + Reminder
Number = Number //10
print(" Reverse of entered number is = %d" %Reverse)
reverse(Number)

Note: Please dont change the intendation

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote