Bez popisu

Lab-checkpoint.ipynb 2.3KB

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