擅长:python、mysql、java
<p>如果您只想在类之外定义变量,则不需要使用<code>global</code>关键字,除非您计划对其进行修改。如果您只想读取变量而不想修改它,您可以执行以下操作。你知道吗</p>
<pre><code>ask = input("What type you are writing? (absolute value and phase angle or real and imaginary parts)")
class ComplexMethods:
if ask == "real and imaginary parts":
pass
if ask == "real and imaginary parts":
firstcomplexreal = float(input("Enter real part of first complex number: "))
firstcompleximaginary = float(input("Enter imaginary part of first complex number: "))
secondcomplexreal = float(input("Enter real part of second complex number: "))
secondcompleximaginary = float(input("Enter imaginary part of second complex number: "))
complexnumbers = ComplexMethods(firstcomplexreal, firstcompleximaginary, secondcomplexreal,
secondcompleximaginary)
</code></pre>