Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a89787

Browse files
committed
Fix FizzBuzz
1 parent c3e61cb commit 4a89787

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

samples/core/guide/autograph.ipynb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,24 +365,26 @@
365365
"cell_type": "code",
366366
"source": [
367367
"@autograph.convert()\n",
368-
"def fizzbuzz(num):\n",
369-
" if num % 3 == 0 and num % 5 == 0:\n",
370-
" return 'FizzBuzz'\n",
371-
" elif num % 3 == 0:\n",
372-
" return 'Fizz'\n",
373-
" elif num % 5 == 0:\n",
374-
" return 'Buzz'\n",
375-
" else:\n",
376-
" return tf.as_string(num)\n",
368+
"def fizzbuzz(i, n):\n",
369+
" while i < n:\n",
370+
" msg = ''\n",
371+
" if i % 3 == 0:\n",
372+
" msg += 'Fizz'\n",
373+
" if i % 5 == 0:\n",
374+
" msg += 'Buzz'\n",
375+
" if msg == '':\n",
376+
" msg = tf.as_string(i)\n",
377+
" print(msg)\n",
378+
" i += 1\n",
379+
" return i\n",
377380
"\n",
378381
"with tf.Graph().as_default():\n",
382+
" final_i = fizzbuzz(tf.constant(10), tf.constant(16))\n",
379383
" # The result works like a regular op: takes tensors in, returns tensors.\n",
380384
" # You can inspect the graph using tf.get_default_graph().as_graph_def()\n",
381-
" num = tf.placeholder(tf.int32)\n",
382-
" result = fizzbuzz(num)\n",
383385
" with tf.Session() as sess:\n",
384-
" for n in range(10,16):\n",
385-
" print(sess.run(result, feed_dict={num:n}))"
386+
" sess.run(final_i)\n",
387+
"\n"
386388
],
387389
"execution_count": 0,
388390
"outputs": []

0 commit comments

Comments
 (0)