我正在尝试使用可视化逻辑流程图来编写python程序。我就是不能让它工作。怎么了?请帮忙!对不起,我是个新手,只是不明白。 以下是我目前所掌握的情况:
#---------------------------------------------------------------------
# Programmer: Les
# Program name: Program to define an array
# Date written: November 08, 2013
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Introduction lines
print("-"*50 + "\n");
print(("Final Project ---> Rolling a Die") + "\n");
print(("Written by Les") + "\n");
print("-"*50 + "\n");
print(" \n");
#---------------------------------------------------------------------
# Define first array
firstCounters = 1 * 6
#---------------------------------------------------------------------
# Input for first round
firstRollsToMake = int(input("Please enter how many times the die should be rolled in the first round ---> \n "));
print(" \n");
#---------------------------------------------------------------------
# Make die
import random
def dice(sides=6):
return random.randint(1,sides)
#---------------------------------------------------------------------
# Rolling the die
for firstRoll in range(1, firstRollsToMake, 1):
dieValue = float(random.randint(min,max));
firstCounters[dieValue] = (firstCounters[dieValue] + 1);
# End for loop
print();
print("-"*50 + "\n");
print(" \n");
#---------------------------------------------------------------------
# Display the percentages
print(format("The value ") + format(firstRollStats) + format(" was rolled ") + format(firstCounters(firstRollStats)) + format(" times") + format(" \n"));
diePercentageOne = (firstCounters(firstRollStats))/firstRollsToMake
print(format(" or ") + format(FormatPercent(diePercentageOne)) + format(" \n"));
#---------------------------------------------------------------------
# Display histogram results
print(format("Below are the results in histogram form\n"));
for histogram in range(1, 6, 1):
print(format(histogram) + (" : "));
for circleLoop in range(1, firstCounters[histogram], 1):
print(format("0"));
print(format(" \n"));
print(format(" \n"));
#---------------------------------------------------------------------
# Define second array
secondCounters = 1 * 6
#---------------------------------------------------------------------
# Input for second round
secondRollsToMake = int(input("Please enter how many times the die should be rolled in the second round ---> \n "));
print(" \n");
#---------------------------------------------------------------------
# Rolling the die again
for secondRoll in range(1, secondRollsToMake, 1):
dieValueTwo = float(random.randint(min,max));
secondCounters[dieValueTwo] = (secondCounters[dieValueTwo] + 1);
# End for loop
print();
print("-"*50 + "\n");
print(" \n");
#---------------------------------------------------------------------
# Display the second percentages
print(format("The value ") + format(secondRollStats) + format(" was rolled ") + format(secondCounters(secondRollStats)) + format(" times") + format(" \n"));
diePercentageTwo = (secondCounters(secondRollStats))/secondRollsToMake
print(format(" or ") + format(FormatPercent(diePercentageTwo)) + format(" \n"));
#---------------------------------------------------------------------
# Display second histogram results
print(format("Below are the results in histogram form\n"));
for histogramTwo in range(1, 6, 1):
print(format(histogramTwo) + (" : "));
for circleLoop in range(1, secondCounters[histogramTwo], 1):
print(format("0"));
print(format(" \n"));
print(format(" \n"));
#---------------------------------------------------------------------
# Number of times rolled comment
print(format("Comment on the number of times rolled:\n"));
print(format("\n"));
while (firstRollsToMake == secondRollsToMake):
if (firstRollsToMake == secondRollsToMake):
print(format("Since the die was rolled the same amount of times in both rounds, the results are not skewed and can be compared and contrasted fairly\n"));
elif (firstRollsToMake < secondRollsToMake):
print(format("Since the die was rolled fewer times in the first round than the second, the results are skewed and cannot be compared and contrasted fairly\n"));
else:
print(format("Since the die was rolled more times in the first round than the second, the results are skewed and cannot be compared and contrasted fairly\n"));
#---------------------------------------------------------------------
# End program
我已经用同样的任务回答了你的两个朋友:
你可以把对你有用的部分拿出来。这也应该包括后续的问题,如:“我如何打印整齐”和“如何绘制直方图”。在
示例:
^{pr2}$相关问题 更多 >
编程相关推荐