擅长:python、mysql、java
<p>这将是Python 3中函数的一个替换项:</p>
<pre><code>def comparison():
while True:
print("Welcome to the comparison function")
a = int(input("Enter your first number for value a, then hit enter key:"))
b = int(input("Enter your second number for value b, then hit enter key:"))
# Recommended replacement for cmp(a, b) in Python 3
# https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
answer = (a > b) - (a < b)
print(answer)
response = input("Would you like to perform another comparison? (yes/no)")
while response.lower() not in ['yes', 'no']:
response = input("please enter proper response: ")
if response.lower() == "yes":
print("Thank you!")
else:
print("Thank you, have a great day!")
break
comparison()
</code></pre>