这是我试图运行的代码......
export class HomePage {
Products: Product[];
Baners: Baner[];
constructor(private navCtrl: NavController,
private productsService: ProductsService,
private BannerService: BanersService) {
}
/**
* Get products
*/
loadProducts(): void {
this.productsService.getOnHomepage().subscribe((products) => {
this.Products = products;
});
}
/**
* get baners
*/
loadBaners(): void {
this.BannerService.getOnHomepage().subscribe((baners) => {
this.Baners = baners;
});
}
loadData(): void {
// I want to show the loader
this.loadProducts();
this.loadBaners();
//I want to hide the loader
}
ionViewWillEnter(){
this.loadData();
}
}
scoreCount = int(input("How many scores do you want to record?"))
recordedValues = 0
averageScore = totalScore/scoreCount
highestScore = 0
totalScore = 0
如何让while循环结束并显示平均分数/最高分数/记录值?
答案 0 :(得分:2)
你在while循环中输入==而不是=
data-purplecoat-for
所以'录音值'和' totalScore'没有改变。
修改:' khelwood'已在评论中提及。
答案 1 :(得分:1)
您的代码存在很多问题:在averageScore
被定义之前,您尝试将totalScore/scoreCount
分配给totalScore
,有时您会使用==
等式检查器一个赋值运算符,即使它已经被转换,你检查score
是否在int
中,并且你的while循环中的条件有问题。您可以这样做:
用异常处理替换重复类型测试并删除非法变量赋值:
try:
scoreCount = int(input("How many scores do you want to record?"))
except ValueError:
print("\n\nYou need to enter an integer...")
quit()
recordedValues = 0
highestScore = 0
totalScore = 0
将>=
更改为>
以获得最高分,修复变量分配,并使用异常处理替换不需要的类型检查。
while recordedValues <= scoreCount:
try:
score = int(input("\n\nEnter Score: "))
except ValueError:
print('Scores must be numbers.')
quit()
totalScore += score
recordedValues += 1
if score > highestScore:
highestScore = score
print("\n\nThe amount of values recorded:", recordedValues)
print("\n\nThe average score:", totalScore / scoreCount)
print("\n\nThe highest score:", highestScore)