擅长:python、mysql、java
<p>您的代码表明您根本不熟悉Python的语法及其工作方式。以下是您的错误解释(按您的要求):</p>
<pre><code> 'def'/myName = input() \r
</code></pre>
<p><em>def</em>周围不需要撇号,<em>myName</em>不需要正斜杠。不能将函数设置为在第一行执行某些操作-这是正确的语法:</p>
<pre><code>def foo():
bar = input('carrot: ')
print(bar)
</code></pre>
<p>此外,在执行任何操作之前,需要将<em>input</em>存储在变量中;<em>input</em>接受字符串。你不需要在每一行之后都有回车。在括号后面,你需要一个冒号。你知道吗</p>
<pre><code> /myName = 'Albert' \r
</code></pre>
<p>不能将函数设置为等于字符串。你知道吗</p>
<pre><code>text_file = open("C:\Output.txt", "w") \r
text_file.write("myName") \r
</code></pre>
<p><em>myName</em>是一个变量,而不是字符串,因此不需要引号。你知道吗</p>
<pre><code> text_file.close()
</code></pre>
<p>以下是工作代码:</p>
<pre><code>myName = input('Name: ') # ask for input, which will be stored in myName
text_file = open('C:\output.txt', 'w') # open the output file in write mode
text_file.write(myName) # write myName to the output file
</code></pre>
<p>我建议在进一步尝试之前先阅读<a href="https://docs.python.org/3.4/tutorial/" rel="nofollow" title="official tutorial">official Python tutorial</a>。你知道吗</p>