下列说法不正确的是( )。知识点:全局变量
A: x = 5def fun(): x = 2 x = x * 3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 5
B: x = 5def fun(): global x x = 2 x = x*3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 6
C: x = 5def fun(): x = x * 3 print(x ,end=' ')fun()print(x)程序无误,输出的结果为15 15
D: x = 5def fun(): print(x, end=' ')fun()print(x)程序无误,输出的结果为5 5
A: x = 5def fun(): x = 2 x = x * 3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 5
B: x = 5def fun(): global x x = 2 x = x*3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 6
C: x = 5def fun(): x = x * 3 print(x ,end=' ')fun()print(x)程序无误,输出的结果为15 15
D: x = 5def fun(): print(x, end=' ')fun()print(x)程序无误,输出的结果为5 5
举一反三
- 下列程序的输出结果是___________。 x = 1 def fun: global x x = 2 fun print(x)
- 如下程序的输出结果是___________def fun(): return lambda x,y:x*x+y*y fx=fun() print(fx(3,4))
- 以下代码的输出结果是(_____)。def fun(num): num *= 2 x = 20 fun(x) print(x) A: 40 B: 10 C: 20 D: 报错
- def fun(x,y): global x,y t=x x=y y=t x=0 y=1 fun(x,y) print(x,y) 结果是 1 0
- 下面程序段执行结果为( )。 x = 5 : y = -6 If not x > 0 Then x = y – 3 Else y = x + 3 End If Print x - y; y - x