擅长:python、mysql、java
<p>尝试使用else语句。你知道吗</p>
<p>除了捕获打印外,请让脚本继续运行。它将继续执行所有if语句,即使捕获被命中。您要做的是在点击except时跳过函数的主要逻辑。使用try-catch ELSE-finally块的<strong>ELSE</strong>子句。你知道吗</p>
<pre><code>import random
def Normal_Guess():
number = round(random.uniform(0.0, 100.0),2)
guess = ""
while guess != number:
try:
guess = float(input("Please guess a number between 0 and 100: "))
except (ValueError, TypeError):
print ("That isn't even a number!")
else:
if guess < number and guess >= 0:
print ("You need to guess higher!")
elif guess > number and guess <= 100:
print ("You need to guess lower!")
elif guess == number:
print("Congratulations! You guessed the number!")
elif guess < 0 or guess > 100:
print ("The number you guessed is not between 0 and 100")
else:
print("That isn't even a number!")
Normal_Guess()
</code></pre>