我正在跟踪CS50P关于YouTube和学习均等的条件。我将代码可视化,以便更好地理解和混淆为什么在执行的第二步中,我的代码从main()跳到def is_even(n)。
1 def main():
2 x = int(input("whats the value of x? "))
3 if is_even(x):
4 print("even")
5 else:
6 print("odd")
7
8 def is_even(n):
9 if n % 2 == 0:
10 return True
11 else:
12 return False
13
14 main()

发布于 2022-07-24 08:24:50
你看错了显示屏。它不是从main()跳到def is_even(n):。显示是说def刚刚执行(定义了is_even函数),接下来要发生的事情是main()行,它将调用main函数。
注意,is_even函数本身尚未执行。定义is_even的代码已经执行。
https://stackoverflow.com/questions/73096784
复制相似问题