{"id":755371,"student_id":10,"content":"import random\n\ndef get_random_number(start, end):\n \"\"\"Generate a random number between start and end (inclusive).\"\"\"\n return random.randint(start, end)\n\ndef get_user_guess():\n \"\"\"Prompt the user for a guess and return it.\"\"\"\n while True:\n try:\n guess = int(input(\"Enter your guess: \"))\n return guess\n except ValueError:\n print(\"Invalid input. Please enter an integer.\")\n\ndef check_guess(guess, target):\n \"\"\"Check the user's guess against the target number.\"\"\"\n if guess \u003c target:\n return \"low\"\n elif guess \u003e target:\n return \"high\"\n else:\n return \"correct\"\n\ndef play_game():\n \"\"\"Play a single game of number guessing.\"\"\"\n print(\"Welcome to the Number Guessing Game!\")\n start = 1\n end = 100\n target = get_random_number(start, end)\n attempts = 0\n print(f\"I have chosen a number between {start} and {end}. Try to guess it!\")\n\n while True:\n guess = get_user_guess()\n attempts += 1\n result = check_guess(guess, target)\n \n if result == \"low\":\n print(\"Your guess is too low.\")\n elif result == \"high\":\n print(\"Your guess is too high.\")\n elif result == \"correct\":\n print(f\"Congratulations! You've guessed the correct number in {attempts} attempts.\")\n break\n\ndef main():\n \"\"\"Main function to control the game flow.\"\"\"\n while True:\n play_game()\n play_again = input(\"Do you want to play again? (yes/no): \").strip().lower()\n if play_again != \"yes\":\n print(\"Thank you for playing! Goodbye!\")\n break\n\n\n\n","created_at":"2024-05-21T18:03:23.659+08:00","updated_at":"2024-05-21T18:10:25.459+08:00","name":"w","language":"python","screenshot":{"url":null},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":240,"hashid":"zpeszwewj","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":16867618,"file_name":"cloud.png","project_id":755371,"asset_id":302343,"created_at":"2024-05-21T18:03:23.665+08:00","updated_at":"2024-05-21T18:03:23.665+08:00"},{"id":16867619,"file_name":"bg.jpg","project_id":755371,"asset_id":302344,"created_at":"2024-05-21T18:03:23.666+08:00","updated_at":"2024-05-21T18:03:23.666+08:00"},{"id":16867620,"file_name":"calm.mp3","project_id":755371,"asset_id":302345,"created_at":"2024-05-21T18:03:23.667+08:00","updated_at":"2024-05-21T18:03:23.667+08:00"},{"id":16867621,"file_name":"koding.png","project_id":755371,"asset_id":302346,"created_at":"2024-05-21T18:03:23.668+08:00","updated_at":"2024-05-21T18:03:23.668+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦