{"id":978370,"date":"2024-12-27T06:37:12","date_gmt":"2024-12-26T22:37:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/978370.html"},"modified":"2024-12-27T06:37:14","modified_gmt":"2024-12-26T22:37:14","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e4%ba%92%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/978370.html","title":{"rendered":"python\u5982\u4f55\u505a\u4e92\u52a8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24203400\/117c9580-09ad-4f66-ae09-551f8745b489.webp\" alt=\"python\u5982\u4f55\u505a\u4e92\u52a8\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u4e92\u52a8\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u8f93\u5165\u51fd\u6570\u4e0e\u7528\u6237\u4ea4\u4e92\u3001\u901a\u8fc7GUI\u5e93\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u3001\u4ee5\u53ca\u501f\u52a9\u7f51\u7edc\u6846\u67b6\u5f00\u53d1\u4ea4\u4e92\u5f0fWeb\u5e94\u7528\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u5177\u4f53\u5e94\u7528\u9700\u8981\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u3002\u4e0b\u9762\u5c06\u5bf9\u4f7f\u7528\u8f93\u5165\u51fd\u6570\u4e0e\u7528\u6237\u4ea4\u4e92\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684<code>input()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4e0e\u7528\u6237\u7684\u57fa\u672c\u4ea4\u4e92\u3002<code>input()<\/code>\u51fd\u6570\u7528\u4e8e\u4ece\u7528\u6237\u83b7\u53d6\u8f93\u5165\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u5b57\u7b26\u4e32\u8fd4\u56de\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u547d\u4ee4\u884c\u7a0b\u5e8f\u4e2d\u975e\u5e38\u5e38\u89c1\u3002\u901a\u8fc7\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u6839\u636e\u7528\u6237\u7684\u9700\u6c42\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668\u7a0b\u5e8f\uff0c\u63d0\u793a\u7528\u6237\u8f93\u5165\u4e24\u4e2a\u6570\u5b57\u548c\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u7136\u540e\u8f93\u51fa\u8ba1\u7b97\u7ed3\u679c\u3002\u5c3d\u7ba1\u8fd9\u79cd\u4ea4\u4e92\u65b9\u5f0f\u76f8\u5bf9\u7b80\u5355\uff0c\u4f46\u5b83\u5728\u6784\u5efa\u547d\u4ee4\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528INPUT\u51fd\u6570\u4e0e\u7528\u6237\u4ea4\u4e92<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c<code>input()<\/code>\u51fd\u6570\u662f\u5b9e\u73b0\u7528\u6237\u4ea4\u4e92\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002<code>input()<\/code>\u51fd\u6570\u5141\u8bb8\u7a0b\u5e8f\u63a5\u6536\u7528\u6237\u7684\u8f93\u5165\uff0c\u5e76\u53ef\u4ee5\u6839\u636e\u8fd9\u4e9b\u8f93\u5165\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u57fa\u672c\u7528\u6cd5<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u6682\u505c\u5e76\u7b49\u5f85\u7528\u6237\u8f93\u5165\u6570\u636e\u3002\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u4f1a\u88ab\u4f5c\u4e3a\u5b57\u7b26\u4e32\u8fd4\u56de\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">name = input(&quot;\u8bf7\u8f93\u5165\u60a8\u7684\u540d\u5b57: &quot;)<\/p>\n<p>print(f&quot;\u60a8\u597d, {name}!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7a0b\u5e8f\u63d0\u793a\u7528\u6237\u8f93\u5165\u4ed6\u4eec\u7684\u540d\u5b57\uff0c\u7136\u540e\u6253\u5370\u51fa\u4e00\u4e2a\u95ee\u5019\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/li>\n<\/ol>\n<p><p>\u56e0\u4e3a<code>input()<\/code>\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u59cb\u7ec8\u662f\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u5728\u9700\u8981\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u6216\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u8f93\u5165\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">age = input(&quot;\u8bf7\u8f93\u5165\u60a8\u7684\u5e74\u9f84: &quot;)<\/p>\n<p>age = int(age)<\/p>\n<p>print(f&quot;\u60a8\u57285\u5e74\u540e\u7684\u5e74\u9f84\u5c06\u662f {age + 5}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u7528\u6237\u8f93\u5165\u7684\u5e74\u9f84\u4ece\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\uff0c\u4ee5\u4fbf\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u901a\u8fc7GUI\u5e93\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u4e2a\u5e93\u7528\u4e8e\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\uff0c\u5982Tkinter\u3001PyQt\u548cKivy\u7b49\u3002\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u521b\u5efa\u66f4\u5177\u4ea4\u4e92\u6027\u548c\u89c6\u89c9\u5438\u5f15\u529b\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528Tkinter<\/li>\n<\/ol>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u4f7f\u7528\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Tkinter\u521b\u5efa\u7b80\u5355\u7a97\u53e3\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>def say_hello():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u7b80\u5355\u7684Tkinter\u7a97\u53e3&quot;)<\/p>\n<p>hello_button = tk.Button(root, text=&quot;\u70b9\u51fb\u6211&quot;, command=say_hello)<\/p>\n<p>hello_button.pack()<\/p>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7a0b\u5e8f\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u6309\u94ae\u7684\u7a97\u53e3\uff0c\u7528\u6237\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u4f1a\u5728\u63a7\u5236\u53f0\u8f93\u51fa&quot;Hello, World!&quot;\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528PyQt<\/li>\n<\/ol>\n<p><p>PyQt\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684GUI\u5e93\uff0c\u652f\u6301\u66f4\u591a\u7684\u63a7\u4ef6\u548c\u590d\u6742\u7684\u5e03\u5c40\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528PyQt\u521b\u5efa\u7b80\u5355\u7a97\u53e3\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout<\/p>\n<p>def say_hello():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<p>app = QApplication([])<\/p>\n<p>window = QWidget()<\/p>\n<p>window.setWindowTitle(&#39;\u7b80\u5355\u7684PyQt\u7a97\u53e3&#39;)<\/p>\n<p>layout = QVBoxLayout()<\/p>\n<p>hello_button = QPushButton(&#39;\u70b9\u51fb\u6211&#39;)<\/p>\n<p>hello_button.clicked.connect(say_hello)<\/p>\n<p>layout.addWidget(hello_button)<\/p>\n<p>window.setLayout(layout)<\/p>\n<p>window.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7a0b\u5e8f\u521b\u5efa\u4e86\u4e00\u4e2a\u7a97\u53e3\uff0c\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u4f1a\u5728\u63a7\u5236\u53f0\u8f93\u51fa&quot;Hello, World!&quot;\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u501f\u52a9\u7f51\u7edc\u6846\u67b6\u5f00\u53d1\u4ea4\u4e92\u5f0fWeb\u5e94\u7528<\/p>\n<\/p>\n<p><p>Python\u4e2d\u6709\u8bb8\u591a\u7f51\u7edc\u6846\u67b6\uff0c\u5982Django\u3001Flask\u7b49\uff0c\u53ef\u4ee5\u7528\u4e8e\u5f00\u53d1\u4ea4\u4e92\u5f0fWeb\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528Flask<\/li>\n<\/ol>\n<p><p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u6846\u67b6\uff0c\u9002\u5408\u4e8e\u5c0f\u578b\u9879\u76ee\u6216\u539f\u578b\u5f00\u53d1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Flask\u521b\u5efa\u7b80\u5355Web\u5e94\u7528\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, render_template_string<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;])<\/p>\n<p>def index():<\/p>\n<p>    if request.method == &#39;POST&#39;:<\/p>\n<p>        name = request.form[&#39;name&#39;]<\/p>\n<p>        return f&#39;\u60a8\u597d, {name}!&#39;<\/p>\n<p>    return &#39;&#39;&#39;<\/p>\n<p>        &lt;form method=&quot;post&quot;&gt;<\/p>\n<p>            \u540d\u5b57: &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;<\/p>\n<p>            &lt;input type=&quot;submit&quot; value=&quot;\u63d0\u4ea4&quot;&gt;<\/p>\n<p>        &lt;\/form&gt;<\/p>\n<p>    &#39;&#39;&#39;<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7a0b\u5e8f\u521b\u5efa\u4e86\u4e00\u4e2aWeb\u8868\u5355\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165\u4ed6\u4eec\u7684\u540d\u5b57\uff0c\u7136\u540e\u7a0b\u5e8f\u4f1a\u5728\u9875\u9762\u4e0a\u663e\u793a\u95ee\u5019\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528Django<\/li>\n<\/ol>\n<p><p>Django\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Web\u6846\u67b6\uff0c\u9002\u5408\u4e8e\u6784\u5efa\u590d\u6742\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Django\u521b\u5efa\u7b80\u5355Web\u5e94\u7528\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5Django\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install django<\/p>\n<p>django-admin startproject mysite<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd mysite<\/p>\n<p>python manage.py startapp myapp<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5728<code>myapp\/views.py<\/code>\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u89c6\u56fe\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from django.http import HttpResponse<\/p>\n<p>def index(request):<\/p>\n<p>    return HttpResponse(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728<code>mysite\/urls.py<\/code>\u4e2d\u914d\u7f6eURL\u6a21\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from django.contrib import admin<\/p>\n<p>from django.urls import path<\/p>\n<p>from myapp import views<\/p>\n<p>urlpatterns = [<\/p>\n<p>    path(&#39;admin\/&#39;, admin.site.urls),<\/p>\n<p>    path(&#39;&#39;, views.index),<\/p>\n<p>]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u8fd0\u884c\u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python manage.py runserver<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8bbf\u95ee<code>http:\/\/127.0.0.1:8000\/<\/code>\uff0c\u4f60\u4f1a\u770b\u5230\u9875\u9762\u4e0a\u663e\u793a&quot;Hello, World!&quot;\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5728Python\u4e2d\u5b9e\u73b0\u66f4\u9ad8\u7ea7\u7684\u4e92\u52a8\u529f\u80fd<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u7684\u8f93\u5165\u8f93\u51fa\u548cGUI\u4ea4\u4e92\uff0cPython\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5176\u4ed6\u6280\u672f\u5b9e\u73b0\u66f4\u9ad8\u7ea7\u7684\u4e92\u52a8\u529f\u80fd\uff0c\u4f8b\u5982\u5b9e\u65f6\u6570\u636e\u5904\u7406\u3001\u8bed\u97f3\u8bc6\u522b\u3001\u56fe\u50cf\u5904\u7406\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b9e\u65f6\u6570\u636e\u5904\u7406<\/li>\n<\/ol>\n<p><p>Python\u53ef\u4ee5\u4e0e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u548c\u5de5\u5177\u7ed3\u5408\uff0c\u5904\u7406\u5b9e\u65f6\u6570\u636e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u4e0eApache Kafka\u8fdb\u884c\u96c6\u6210\uff0c\u5b9e\u73b0\u6570\u636e\u6d41\u5904\u7406\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8bed\u97f3\u8bc6\u522b<\/li>\n<\/ol>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u7528\u4e8e\u8bed\u97f3\u8bc6\u522b\uff0c\u5982SpeechRecognition\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u8bed\u97f3\u8bc6\u522b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import speech_recognition as sr<\/p>\n<p>recognizer = sr.Recognizer()<\/p>\n<p>with sr.Microphone() as source:<\/p>\n<p>    print(&quot;\u8bf7\u8bf4\u8bdd...&quot;)<\/p>\n<p>    audio = recognizer.listen(source)<\/p>\n<p>try:<\/p>\n<p>    text = recognizer.recognize_google(audio, language=&quot;zh-CN&quot;)<\/p>\n<p>    print(f&quot;\u60a8\u8bf4\u7684\u662f: {text}&quot;)<\/p>\n<p>except sr.UnknownValueError:<\/p>\n<p>    print(&quot;\u62b1\u6b49\uff0c\u6211\u65e0\u6cd5\u8bc6\u522b\u60a8\u8bf4\u7684\u8bdd&quot;)<\/p>\n<p>except sr.RequestError:<\/p>\n<p>    print(&quot;\u62b1\u6b49\uff0c\u65e0\u6cd5\u8fde\u63a5\u5230\u8bed\u97f3\u8bc6\u522b\u670d\u52a1&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u56fe\u50cf\u5904\u7406<\/li>\n<\/ol>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff0c\u5982OpenCV\u548cPillow\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<p>image = image.rotate(45)<\/p>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u6280\u672f\uff0cPython\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u4e92\u52a8\u529f\u80fd\uff0c\u6ee1\u8db3\u4e0d\u540c\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u547d\u4ee4\u884c\u7a0b\u5e8f\u8fd8\u662f\u590d\u6742\u7684Web\u5e94\u7528\uff0cPython\u90fd\u80fd\u63d0\u4f9b\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u5e93\uff0c\u5b9e\u73b0\u5f3a\u5927\u7684\u4ea4\u4e92\u529f\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u7528\u6237\u8f93\u5165\u7684\u4e92\u52a8\u529f\u80fd\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>input()<\/code>\u51fd\u6570\u6765\u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165\u3002\u901a\u8fc7\u8fd9\u4e2a\u51fd\u6570\uff0c\u7a0b\u5e8f\u4f1a\u6682\u505c\u5e76\u7b49\u5f85\u7528\u6237\u8f93\u5165\u6570\u636e\u3002\u53ef\u4ee5\u5c06\u8f93\u5165\u7684\u5185\u5bb9\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u4f7f\u7528\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">user_input = input(&quot;\u8bf7\u8f93\u5165\u60a8\u7684\u540d\u5b57\uff1a&quot;)\nprint(f&quot;\u4f60\u597d\uff0c{user_input}\uff01&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u63d0\u793a\u7528\u6237\u8f93\u5165\u540d\u5b57\uff0c\u5e76\u6253\u5370\u51fa\u4e00\u6761\u95ee\u5019\u4fe1\u606f\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u66f4\u590d\u6742\u7684\u4e92\u52a8\u754c\u9762\uff1f<\/strong><br \/>\u5bf9\u4e8e\u9700\u8981\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7684\u4e92\u52a8\uff0cPython\u63d0\u4f9b\u4e86\u591a\u4e2a\u5e93\uff0c\u5982Tkinter\u3001PyQt\u548cKivy\u3002Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u9002\u5408\u521b\u5efa\u7b80\u5355\u7684\u7a97\u53e3\u5e94\u7528\u7a0b\u5e8f\u3002PyQt\u9002\u7528\u4e8e\u66f4\u590d\u6742\u7684\u5e94\u7528\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63a7\u4ef6\u548c\u529f\u80fd\u3002\u800cKivy\u5219\u7528\u4e8e\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\uff0c\u652f\u6301\u89e6\u6478\u8f93\u5165\uff0c\u9002\u5408\u79fb\u52a8\u8bbe\u5907\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u57fa\u4e8e\u6587\u672c\u7684\u4e92\u52a8\u6e38\u620f\uff1f<\/strong><br \/>\u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e\u6587\u672c\u7684\u4e92\u52a8\u6e38\u620f\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u548c\u6761\u4ef6\u8bed\u53e5\u5b9e\u73b0\u3002\u7528\u6237\u901a\u8fc7\u8f93\u5165\u6307\u4ee4\u6765\u4e0e\u6e38\u620f\u8fdb\u884c\u4e92\u52a8\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u731c\u6570\u5b57\u6e38\u620f\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\n\nnumber_to_guess = random.randint(1, 100)\nuser_guess = 0\n\nwhile user_guess != number_to_guess:\n    user_guess = int(input(&quot;\u731c\u4e00\u4e2a1\u5230100\u4e4b\u95f4\u7684\u6570\u5b57\uff1a&quot;))\n    if user_guess &lt; number_to_guess:\n        print(&quot;\u592a\u5c0f\u4e86\uff0c\u518d\u8bd5\u8bd5\uff01&quot;)\n    elif user_guess &gt; number_to_guess:\n        print(&quot;\u592a\u5927\u4e86\uff0c\u518d\u8bd5\u8bd5\uff01&quot;)\n    else:\n        print(&quot;\u606d\u559c\u4f60\uff0c\u731c\u5bf9\u4e86\uff01&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u6e38\u620f\u901a\u8fc7\u4e0d\u65ad\u63d0\u793a\u7528\u6237\u8f93\u5165\uff0c\u76f4\u5230\u4ed6\u4eec\u731c\u5bf9\u4e3a\u6b62\uff0c\u589e\u5f3a\u4e86\u4e92\u52a8\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u4e92\u52a8\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u8f93\u5165\u51fd\u6570\u4e0e\u7528\u6237\u4ea4\u4e92\u3001\u901a\u8fc7GUI\u5e93\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u3001\u4ee5 [&hellip;]","protected":false},"author":3,"featured_media":978373,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978370"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=978370"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978370\/revisions"}],"predecessor-version":[{"id":978375,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978370\/revisions\/978375"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/978373"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=978370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=978370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=978370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}