Question: I need help getting my program to reject a negative input from the user. Here is what I have: #short description of what the program

I need help getting my program to reject a negative input from the user.

Here is what I have:

#short description of what the program will do print("Hello, this program will ask you to enter a non-negative decimal integer. The program will then show the binary equivalent of the integer you choose.")

#ask the user to enter the non-negative decimal integer number= int(input("Enter a non-negative decimal integer: ")) while number< 0: print("Number Cannot Be Negative!! Try again...") #create a variable containing an empty character string output=' ' #create a copy of user's variable named "working" working = number #reject input less than zero

while True: #if working number is odd, prepend "1" to string variable if working%2==1: output="1"+output else: output="0"+output #if working number is even, preven "O" to string variable #print working number and character string print(str(working) + " " + output) #divide working number by 2, throwing away remainder working//=2 #stop when working number gets to zero if working==0: break #print user's original number and it's binary representation print("I think your original binary number " + str(number) + " is " +output+ " in binary.")

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!