1

So, I'm doing a project for school in python that converts normal numbers to binary and I've stopped here because of a "while loop" error, here's the code:

number = float(input("What's your number: "))
binary = 0
is_integer = True
binary_lenght = len(int(binary)

while number < 0:
  number = number/2
  is_integer = (number).is_integer()
  binary_lenght = len(binary)
  if is_integer == True:
    binary = binary + "0"
    binary = float(binary)

and I get

  File "main.py", line 6
    while number < 0:
    ^
SyntaxError: invalid syntax
1
  • 1
    You have missing closing parenthesis on previous line. Commented Dec 18, 2021 at 10:16

1 Answer 1

2

You missed a closing parenthesis on line binary_lenght = len(int(binary)

Here is the code after fix.

number = float(input("What's your number: "))
binary = 0
is_integer = True
binary_lenght = len(int(binary))

while number < 0:
  number = number/2
  is_integer = (number).is_integer()
  binary_lenght = len(binary)
  if is_integer == True:
    binary = binary + "0"
    binary = float(binary)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.