我正在学习C#atm并试图解决我书中描述的一个问题.写一个程序,计算和打印(精度为0.001)序列1 + 1/2 - 1/3 + 1/4 - 1/5 + ....我知道这是一个常见的问题,但我几乎失去了整整一天要解决它,但我不能单独做(也许我没有努力).
static void Main()
{
double sum = 0D;
double sum1 = 0d;
int i = 1;
while ( i <100)
{
i++;
if (i % 2 == 0)
{
sum1 = sum1 +(1 / i);
}
else
{
sum1 = sum1 -(1 / i);
}
sum = sum1 + sum;
Console.WriteLine(Math.Round(sum, 3));
}
}
Run Code Online (Sandbox Code Playgroud) 我有功课要做,我做了.我95%肯定它是一个核心代码.我不知道为什么但不幸的是我在其中一行中得到了Syntax错误.这是我的代码:
month = 1
totalPaid = 0
while month <= 12:
print('Month: ' + str(month))
print('Minimum monthly payment: ' + str(round(monthlyPaymentRate * balance), 2)
balance = round((balance - (monthlyPaymentRate * balance)) * (1 + (annualInterestRate/12)),2)
print('Remaining balance: ' + str(round(balance, 2)))
month = month + 1
totalPaid = totalPaid + round((monthlyPaymentRate * balance), 2)
print('Total paid: ' + str(totalPaid))
print('Remaining balance: ' + str(balance))
Run Code Online (Sandbox Code Playgroud)
我在这一行得到了语法错误:balance = round((余额 - (monthlyPaymentRate*余额))*(1 +(annualInterestRate/12)),2).它可能是非常简单的东西,但我是Python的新手,无法理解究竟是什么问题,我知道Python对空格和缩进非常敏感,我对此很谨慎.有什么建议 ?
我有一个任务是创建一个类Student并创建一个方法,只有当他们的名字在使用LINQ查询运算符的字母顺序排在他们的姓氏之前时才从数组中选择Students.我写过这Student堂课:
public class Student
{
private string firstName;
private string familyName;
private int age;
public Student(string firstName, string familyName, int age)
: this()
{
this.firstName = firstName;
this.familyName = familyName;
this.age = age;
}
public Student()
{
firstName = "Dancho";
familyName = "Mastikata";
age = 24;
this.firstName = firstName;
this.familyName = familyName;
this.age = age;
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string FamilyName
{ …Run Code Online (Sandbox Code Playgroud)