-1

I am basically trying to make a database in Python, in which each ''data'' would consist of a string and a number equivalent (or something close to it), and I am looking for a way which would allow an end-user to enter an input corresponding to one of the strings in the database and refer it to its corresponding float value, to then perform simple arithmetic operations. This is what I made and it does nothing at all

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))

EDIT : I just revisited this page and found the solution to my problem all by myself, all that was missing was the quotation marks in the code and the variable definition together. the correct way to do it is the following:

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))

if this need to be deleted I will do it

Louis Couture
  • 72
  • 1
  • 9

1 Answers1

0

If you want to test the letter that the user typed, you have to compare to a string.

if test == 'c' and test2 == 'd':
    print(c + d)
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • It says it cannot convert c to float – Louis Couture Aug 31 '17 at 03:09
  • You're typing the variable names into the inputs, not numbers like `2.66`? – Barmar Aug 31 '17 at 03:10
  • If you want the user to be able to type any variable name, and then you look up its value, you should use a dictionary, not separate variables. – Barmar Aug 31 '17 at 03:15
  • I am indeed putting the variables names, so I'll guess I'll make a dictionnary – Louis Couture Aug 31 '17 at 03:24
  • I just revisited this page and found the solution to my problem all by myself, all that was missing was the quotation marks in the code. the correct way to do it is the following: 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)) – Louis Couture Jan 10 '18 at 02:59