Nenhuma Descrição

Lab.ipynb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# installation\n",
  8. "ตาม links ต่อไปนี้ \n",
  9. "- https://phoenixnap.com/kb/how-to-install-python-3-windows\n",
  10. "- https://docs.python.org/3/library/venv.html"
  11. ]
  12. },
  13. {
  14. "cell_type": "markdown",
  15. "metadata": {},
  16. "source": [
  17. "# Lab 1.1 \n",
  18. "เขียน program บวกเลข ตั้งแต่ 1 .. n ตัวอย่าง\n",
  19. "n = 10\n",
  20. "r = 1 + 2 + ... + n"
  21. ]
  22. },
  23. {
  24. "cell_type": "code",
  25. "execution_count": 3,
  26. "metadata": {},
  27. "outputs": [
  28. {
  29. "name": "stdout",
  30. "output_type": "stream",
  31. "text": [
  32. "enter a: 10\n",
  33. "enter b: 30\n"
  34. ]
  35. },
  36. {
  37. "data": {
  38. "text/plain": [
  39. "'1030'"
  40. ]
  41. },
  42. "execution_count": 3,
  43. "metadata": {},
  44. "output_type": "execute_result"
  45. }
  46. ],
  47. "source": [
  48. "a = input('enter a: ')\n",
  49. "b = input('enter b: ')\n",
  50. "c = a + b\n",
  51. "c"
  52. ]
  53. },
  54. {
  55. "cell_type": "markdown",
  56. "metadata": {},
  57. "source": [
  58. "# Lab 1.2\n",
  59. "เขียน program ที่เก็บค่าส่วนต่างๆ ของรถยนต์ คันหนึ่งเช่น width, height, length , color และ เป็นสีแดงให้ print \"I love it\" ถ้าไม่ Goodbye\n",
  60. "และถ้า width > 200 ให้ print \"very big car\""
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 8,
  66. "metadata": {},
  67. "outputs": [
  68. {
  69. "name": "stdout",
  70. "output_type": "stream",
  71. "text": [
  72. "...\n",
  73. "I love it\n"
  74. ]
  75. }
  76. ],
  77. "source": [
  78. "car = {'w': 100, 'h':200, 'l':150, 'color': 'red'}\n",
  79. "for k in car:\n",
  80. " if k == 'color':\n",
  81. " if car[k] == \"red\":\n",
  82. " print(\"I love it\")\n",
  83. " else:\n",
  84. " print(\"Goodbye\")\n",
  85. " if k == \"w\":\n",
  86. " if car[k] > 200:\n",
  87. " print(\"Very big car\")\n",
  88. " else:\n",
  89. " print(\"...\")\n",
  90. " "
  91. ]
  92. }
  93. ],
  94. "metadata": {
  95. "kernelspec": {
  96. "display_name": "Python 3",
  97. "language": "python",
  98. "name": "python3"
  99. },
  100. "language_info": {
  101. "codemirror_mode": {
  102. "name": "ipython",
  103. "version": 3
  104. },
  105. "file_extension": ".py",
  106. "mimetype": "text/x-python",
  107. "name": "python",
  108. "nbconvert_exporter": "python",
  109. "pygments_lexer": "ipython3",
  110. "version": "3.8.5"
  111. }
  112. },
  113. "nbformat": 4,
  114. "nbformat_minor": 4
  115. }