Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
4a897878
Commit
4a897878
authored
Jul 19, 2018
by
Mark Daoust
Browse files
Fix FizzBuzz
parent
c3e61cb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
samples/core/guide/autograph.ipynb
samples/core/guide/autograph.ipynb
+15
-13
No files found.
samples/core/guide/autograph.ipynb
View file @
4a897878
...
...
@@ -365,24 +365,26 @@
"cell_type": "code",
"source": [
"@autograph.convert()\n",
"def fizzbuzz(num):\n",
" if num % 3 == 0 and num % 5 == 0:\n",
" return 'FizzBuzz'\n",
" elif num % 3 == 0:\n",
" return 'Fizz'\n",
" elif num % 5 == 0:\n",
" return 'Buzz'\n",
" else:\n",
" return tf.as_string(num)\n",
"def fizzbuzz(i, n):\n",
" while i < n:\n",
" msg = ''\n",
" if i % 3 == 0:\n",
" msg += 'Fizz'\n",
" if i % 5 == 0:\n",
" msg += 'Buzz'\n",
" if msg == '':\n",
" msg = tf.as_string(i)\n",
" print(msg)\n",
" i += 1\n",
" return i\n",
"\n",
"with tf.Graph().as_default():\n",
" final_i = fizzbuzz(tf.constant(10), tf.constant(16))\n",
" # The result works like a regular op: takes tensors in, returns tensors.\n",
" # You can inspect the graph using tf.get_default_graph().as_graph_def()\n",
" num = tf.placeholder(tf.int32)\n",
" result = fizzbuzz(num)\n",
" with tf.Session() as sess:\n",
"
for n in range(10,16):
\n",
"
print(sess.run(result, feed_dict={num:n}))
"
"
sess.run(final_i)
\n",
"
\n
"
],
"execution_count": 0,
"outputs": []
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment