# -*- coding: cp1250 -*-
print ('euklides alpha 1.0')
a = raw_input('podaj liczbę A : ')
b = raw_input('podaj liczbę B : ')
a = float('a')
b = float('b')
if 'a'=='b':
print 'a'
elif 'a' > 'b':
while 'a' > 'b':
print('a'-'b')
if 'a'=='b': break
if 'a' > 'b': continue
elif 'b' > 'a':
while 'b' > 'a':
print('b'-'a')
if 'b'=='a': break
if 'b' > 'a': continue
这是我几个小时前写的代码。现在我得到了一个ValueError: could not convert string to float: a
,我不知道为什么。你能给我解释一下吗?我是初学者。在
您将所有变量括在单引号中,因此比较字符串}中的相同
"a"
与字符串"b"
,而不是将变量a
中包含的浮点数与变量{同样值得指出的是:
这是您的原始代码,用于向用户请求两个浮点数
如果您使用的是Python 2.x,则可以使用
我在下面的评论中被abarnert更正了。只是为了教化:
^{pr2}$如果不是,则可能需要包含try/catch块,该块将强制变量为您需要的类型
浮点函数可以接受字符串,但必须包含可能有符号的十进制数或浮点数。您希望使变量
a
成为浮点,而不是字符'a'
。在您不需要在变量名周围加上
'
。当你在它们周围加上引号'b'
你就是在把它们变成一个字符串。在另一个注意事项是,一旦你接触到那些
while
语句,就没有什么能让你走出困境。在相关问题 更多 >
编程相关推荐