python - 为什么在 Udacity 中没有显示输出,尽管代码在 Jupiter 笔记本中有效?
问题描述
当试图通过仅更改输入来解决 Udacity 中的任务时,代码不想显示任何输出。我试图编辑代码并单击测试运行,但它没有显示任何内容;它只显示“您的代码没有显示输出”。我将代码复制到 Jupiter 笔记本上,它就可以工作了。
代码
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))
解决方案
推荐阅读
- git - 如何在本地清理被提交删除但包含被忽略文件的 git 目录?
- python-3.x - K-Means GridSearchCV 超参数调优
- html - 我需要有关如何使 div 占据父 div verticallt 100% 的帮助
- python - numpy 1-D 数组大小减少而不会丢失绘图的签名
- node.js - 如何在对话框流中提示用户输入条件参数
- postgresql - 无法连接到 Azure 云超大规模 citus
- python - 如何根据pytorch中另一个张量的值将某个张量的值更改为零?
- tensorflow - GPU 版本是否仅适用于 TensorFlow 对象检测?
- javascript - 从异步函数 node.js 返回值
- c# - 如何在 Nuget 命令上使用 Add-Migration 更新数据库?