"while loop" 中的语法无效
Invalid syntax in "while loop"
所以,我在 python 为学校做一个将普通数字转换为二进制的项目,由于“while 循环”错误,我在这里停止了,代码如下:
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)
然后我得到
File "main.py", line 6
while number < 0:
^
SyntaxError: invalid syntax
您错过了第 binary_lenght = len(int(binary)
行的右括号
修复后的代码如下
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)
所以,我在 python 为学校做一个将普通数字转换为二进制的项目,由于“while 循环”错误,我在这里停止了,代码如下:
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)
然后我得到
File "main.py", line 6
while number < 0:
^
SyntaxError: invalid syntax
您错过了第 binary_lenght = len(int(binary)
修复后的代码如下
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)