In: Computer Science
Having indentation problems. I have no idea why one of my breaks are screwing up. This should be a easy fix and thumbs up for you lads out there. here's my code. Ill leave a comment on where the break problem is. Also if you could do be a solid and run it to see if it executes. Thanks!
Python Code:
def to_euro(dollar): return float(dollar)*0.81; def to_yen(dollar): return float(dollar)*106.45; def to_peso(dollar): return float(dollar)*18.58; def main(): while(1): x=input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: "); x=int(x); if(x==1 or x==2 or x==3): break; else: print("Error: Invalid choice"); while(1): y=input("Enter US Dollar: "); y=float(y); if(y<0): print("Can't be negetive"); else: break; #here is the error if(x==1): print("Its is converted to ",to_euro(y)," Euro" ); elif(x==2): print("Its is converted to ",to_yen(y)," Yen" ); else: print("Its is converted to ",to_peso(y)," Peso" ); main()
Explanation:
Here is the code which has the correct indentation, the error was there because, the code was not inside the while loop.
Code:
def to_euro(dollar):
return float(dollar)*0.81
def to_yen(dollar):
return float(dollar)*106.45
def to_peso(dollar):
return float(dollar)*18.58
def main():
while(1):
x=input("Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso:
")
x=int(x)
if(x==1 or x==2 or x==3):
break
else:
print("Error: Invalid choice")
while(1):
y=input("Enter US Dollar: ")
y=float(y)
if(y<0):
print("Can't be negetive")
else:
break
if(x==1):
print("Its is converted to ",to_euro(y)," Euro" )
elif(x==2):
print("Its is converted to ",to_yen(y)," Yen" )
else:
print("Its is converted to ",to_peso(y)," Peso" )
main()
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!