简体   繁体   中英

Python script stopping before completion

I'm Not sure what I'm doing. Why does this stop after asking for Oustanding balance?

x=raw_input('Outstanding Balance:');
y=raw_input('Annual Interest Rate:');
z=raw_input('Monthly Interest Rate:');
a=(x*z)
b=((y/12)*x)
c=(a-b)
d=(x-c)
print ("Minimum monthly Payment:"+(a));
print ("Interest Paid:"+ (b));
print ("Principal Paid:"+(c));
print ("Remaining balance:"+(d))

raw_input waits for user-input so it would appear to have stopped running. You can type in some input and hit return for it to continue.

You have to convert the input to int before doing arithmetic operations on them. Modify it as shown below.

x=int(raw_input('Outstanding Balance:'))
y=int(raw_input('Annual Interest Rate:'))
z=int(raw_input('Monthly Interest Rate:'))
a=x*z
b=((y/12)*x)
c=(a-b)
d=(x-c)
print ("Minimum monthly Payment:"+str(a))
print ("Interest Paid:"+ str(b))
print ("Principal Paid:"+str(c))

print ("Remaining balance:"+str(d))

raw_input() function return a str object, it can't do calculation

Using the build_in function int() to turn x to int using int(x) and the same as y and z.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM