如果这看起来像一个愚蠢的问题我很抱歉,但我对编写代码非常陌生。我刚刚开始学习Java,而且我在编写一个程序时遇到了一些麻烦,我被指示作为一项任务。
我只是好奇我如何计算用户输入的每个值的百分比。我试图找到正确的方法来解决这个问题,以便它可以读取并且可以被Java正确解释,我有点麻烦。
我的目标是计算脂肪,碳水化合物和蛋白质中克数的每个百分比,并将其显示在屏幕上。我并没有要求某人为我做任务,我只是需要一些指导。
谢谢!
//local constants
//local variables
int carb; // amount of carbs entered by user
int fat; // amount of fat entered by user
int pro; // amount of protein entered by user
int sum; // sum of three numbers
//myLib = new Library();
/******************** Start main method *****************/
//Prompt user for amount of carbohydrates
System.out.print("Please enter the amount of carbohydrates: ");
carb = Keyboard.readInt();
//Prompt user for amount of fat
System.out.print("Please enter the amount of fat: ");
fat = Keyboard.readInt();
//Prompt user for amount of protein
System.out.print("Please enter amount of protein: ");
pro = Keyboard.readInt();
//Calculate the sum of the three numbers
sum = carb + fat + pro;
答案 0 :(得分:1)
正如拉曼所说,现在你将这些总和整齐地储存在一个变量中,相对容易计算百分比
import urllib
party_name_list = ["Conservative", "Liberal", "NDP", "Green Party", "Bloc Québécois", "Forces et Démocratie", "Libertarian", "Christian Heritage"]
for party_name in party_name_list:
with urllib.request.urlopen(r"https://represent.opennorth.ca/candidates/house-of-commons/?limit=1000&party_name={}".format(urllib.parse.quote_plus(party_name))) as url:
with open(r"F:\electoral_map\20150914\candidates\candidates_{0}.json".format(party_name), "wb+") as f:
f.write(url.read())
print("finished {0}".format(party_name))
print("all done")