我之前创建了这个成绩簿代码。我在学习C#的过程中学会了通过观看视频来编写它。
当硬编码输入等级时,将成绩插入成绩簿是成功的。我正在尝试更新代码,以便我可以从控制台窗口输入成绩而不是硬编码成绩。
以下代码是我目前所拥有的:
class Program
{
static void Main(string[] args)
{
//SpeechSynthesizer synth = new SpeechSynthesizer();
//synth.Speak("Welcome, to the Grade Book Program.");
//SpeechSynthesizer justMoreToSay = new SpeechSynthesizer();
//justMoreToSay.Speak("Okay, Now that we got that out of the way. May you input the Grades please.");
/*Gradebook book = new Gradebook();
book.AddGrade(91);
book.AddGrade(89);
book.AddGrade(83.5f);
book.AddGrade(78);
book.AddGrade(98);
book.AddGrade(93);
book.AddGrade(79);
book.AddGrade(64);
book.AddGrade(32);
book.AddGrade(45);
book.AddGrade(67);
book.AddGrade(90);
book.AddGrade(58);
book.AddGrade(72);
book.AddGrade(100);
book.AddGrade(85);*/
Console.WriteLine("Please go ahead and Listen to the Voice and input the Grades:");
Gradebook inputValues = new Gradebook();
inputValues.AddGrade(85);
inputValues.AddGrade(62);
GradeStatistics stats = inputValues.ComputeStatistics();
//Console.WriteLine(stats.HighestGrade);
//Console.WriteLine(stats.AverageGrade);
//Console.WriteLine(stats.LowestGrade);
Console.WriteLine("The average for this person is {0} and the Highest grade he made is {1} and the Lowest is {2}. If you May please select any character to exit the program!", stats.AverageGrade, stats.HighestGrade, stats.LowestGrade);
}
}
public class Gradebook
{
public Gradebook()
{
grades = new List<float>();
}
public GradeStatistics ComputeStatistics()
{
GradeStatistics stats = new GradeStatistics();
float sum = 0;
foreach (float grade in grades)
{
{
stats.HighestGrade = Math.Max(grade, stats.HighestGrade);
stats.LowestGrade = Math.Min(grade, stats.LowestGrade);
sum = sum + grade;
}
}
stats.AverageGrade = sum / grades.Count;
return stats;
}
public void AddGrade(float grade)
{
grades.Add(grade);
}
public List<float> grades;
}
答案 0 :(得分:0)
要从控制台读取行并将其转换为整数,您可以使用读取行并将字符串转换为数字表示形式:
Console.Writeline("Enter Number");
var num = Convert.ToInt32(Console.ReadLine());
在循环中执行此操作,直到您收到用户的某种终止输入,例如-1
答案 1 :(得分:0)
试试这个
for index,rows in df.iterrows():
cursor.execute("""update result SET Pay_Agent = ? WHERE SEND_AGENT = ?""",df['PAY_AGENT'][rownum],df['SEND_AGENT'][rownum])
rownum+=1