Python 为什么Udacity中没有显示输出,尽管代码在Jupiter笔记本中工作?

Python 为什么Udacity中没有显示输出,尽管代码在Jupiter笔记本中工作?,python,pandas,machine-learning,deep-learning,output,Python,Pandas,Machine Learning,Deep Learning,Output,当试图通过仅更改输入来解决Udacity中的任务时,代码不希望显示任何输出。我试图编辑代码并单击TestRun,但它没有显示任何内容;它只显示“您的代码显示无输出”。我把代码复制到一个Jupiter笔记本上,它就在那里工作了 代码 您遇到的问题可能不是输出本身,而是之前在练习中未正确设置某些数据。我在另一个练习中遇到了同样的问题,并且能够通过先重置测验,然后逐步填充必要的值来解决它,每一步后面都是“测试运行”,这会产生更好、更详细的错误消息。因此,可以先重置测验,填写weight1、weight

当试图通过仅更改输入来解决Udacity中的任务时,代码不希望显示任何输出。我试图编辑代码并单击TestRun,但它没有显示任何内容;它只显示“您的代码显示无输出”。我把代码复制到一个Jupiter笔记本上,它就在那里工作了

代码


您遇到的问题可能不是输出本身,而是之前在练习中未正确设置某些数据。我在另一个练习中遇到了同样的问题,并且能够通过先重置测验,然后逐步填充必要的值来解决它,每一步后面都是“测试运行”,这会产生更好、更详细的错误消息。因此,可以先重置测验,填写
weight1
weight2
bias
、“测试运行”的值,然后对所有待办事项重复这些步骤。问题可能不是输出本身,而是之前在练习中未正确设置某些数据。我在另一个练习中遇到了同样的问题,并且能够通过先重置测验,然后逐步填充必要的值来解决它,每一步后面都是“测试运行”,这会产生更好、更详细的错误消息。因此,可以先重置测验,填写
weight1
weight2
bias
、“测试运行”的值,然后对所有待办事项重复这些步骤。
import pandas as pd

# TODO: Set weight1, weight2, and bias
weight1 = 1
weight2 = 1
bias = 0.5


# DON'T CHANGE ANYTHING BELOW
# Inputs and outputs
test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
correct_outputs = [False, False, False, True]
outputs = []

# Generate and check output
for test_input, correct_output in zip(test_inputs, correct_outputs):
    linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias
    output = int(linear_combination >= 0)
    is_correct_string = 'Yes' if output == correct_output else 'No'
    outputs.append([test_input[0], test_input[1], linear_combination, output, is_correct_string])

# Print output
num_wrong = len([output[4] for output in outputs if output[4] == 'No'])
output_frame = pd.DataFrame(outputs, columns=['Input 1', '  Input 2', '  Linear Combination', '  Activation Output', '  Is Correct'])
if not num_wrong:
    print('Nice!  You got it all correct.\n')
else:
    print('You got {} wrong.  Keep trying!\n'.format(num_wrong))
print(output_frame.to_string(index=False))