我基本上是在尝试用Python制作一个数据库,其中每个“数据”将由一个字符串和一个等价的数字(或接近它的某个数字)组成,我正在寻找一种方法,允许最终用户输入与数据库中某个字符串相对应的输入,并将其引用到相应的float值,然后执行简单的算术运算。 这是我做的,它什么都不做
c = float(2.66)
d = float(6.68)
test = input('Enter the letter')
test2 = input('Enter the second letter')
if test == c and test2 == d:
print(float(c)+float(d))
编辑: 我只是重新访问了这一页,找到了解决问题的方法,只缺少代码中的引号和变量定义。正确的方法如下:
c = float(2.66)
d = float(6.68)
test = str(input('Enter the letter'))
test2 = str(input('Enter the second letter'))
if test == str('c') and test2 == str('d') :
print(float(c)+float(d))
如果这个需要删除我会做的
如果要测试用户键入的字母,必须将其与字符串进行比较。你知道吗
相关问题 更多 >
编程相关推荐