[英]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))
You have to convert the input to int
before doing arithmetic operations on them.在对它们进行算术运算之前,您必须将输入转换为int
。 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 raw_input() 函数返回一个 str 对象,它不能做计算
Using the build_in function int() to turn x to int using int(x) and the same as y and z.使用 build_in 函数int()使用int(x)将 x 转换为 int,与 y 和 z 相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.