-1

Whats wrong with my code? After the second "input" the program stops...

convr = 0

x = input("Inform value: ")
y = input("Inform if is Dolar (D) or Euro (E): ")

convt = x * convr

if y == "D":
    convr = 1/0.895
    print (convt)
elif y == "E":
    convr = 0.895
    print (convt)
else:
    print ("NOT ALLOWED!")
martineau
  • 119,623
  • 25
  • 170
  • 301
Nelthar
  • 57
  • 9
  • Check this. It may be relevant in your case. I complied your piece of code in python fiddle and I get named error as well. http://stackoverflow.com/questions/2612948/error-in-python-d-not-defined – xCodeZone Sep 21 '16 at 01:04
  • I solved the problem of "convt". But now i dont know a way to multiply the input (that is a string) with a float. – Nelthar Sep 21 '16 at 01:08
  • Use Google, and search for the answer. – MattDMo Sep 21 '16 at 01:20

2 Answers2

3

Because your x variable is a string, you need to transform it to number, eg. float or int.

x = float(input("Inform value: "))
y = input("Inform if is Dolar (D) or Euro (E): ")

if y == "D":
    convr = 1/0.895
    convt = x * convr
    print (convt)
elif y == "E":
    convr = 0.895
    convt = x * convr
    print (convt)
else:
    print ("NOT ALLOWED!")
---------
# Inform value: 2345
# Inform if is Dolar (D) or Euro (E): D
# 2620.1117318435754
Aaron
  • 2,383
  • 3
  • 22
  • 53
0

The program doesn's stop. Just your value is empty. You can see what I mean by changing your print() statements to:

print ('RESULT: ' + convt)

Now, instead of a blank line, you will get "Result: " printed to the screen.

The reason you don't get a value is because of this line:

convt = x * convr

When you run this convr is equal to zero. Any number times by zero equals zero. :)

Andrew Hewitt
  • 518
  • 4
  • 14