When I run my code I get a weird output (listed in question). What do I do?

huangapple go评论99阅读模式
英文:

When I run my code I get a weird output (listed in question). What do I do?

问题

以下是翻译好的代码部分:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()

timmy_the_turtle.shape("turtle")

screen = Screen()
screen.exitonclick()
print("Hi")

请注意,警告信息的翻译不包含在内。

英文:
from turtle import Turtle, Screen

timmy_the_turtle = Turtle()

timmy_the_turtle.shape("turtle")

screen = Screen()
screen.exitonclick()
print("Hi")

When I run this I get this output:

2023-06-18 13:08:23.720 Python[71369:2018591] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.

What do I do?

I am expecting hi to be printed but nothing happens.

答案1

得分: 1

以下是翻译好的部分:

"WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES," appears to be related to macOS-specific functionality and doesn't affect the execution of your code.

Regarding the issue where "Hi" is not being printed, the problem lies in the order of your code. You're calling screen.exitonclick() before printing "Hi," so the program exits immediately without giving you a chance to see the output.

To fix this, you can reorder your code as follows:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")

print("Hi")

screen = Screen()
screen.exitonclick()

With this change, the output "Hi" should be printed before the program exits.

英文:

The message you mentioned, "WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES," appears to be related to macOS-specific functionality and doesn't affect the execution of your code.

Regarding the issue where "Hi" is not being printed, the problem lies in the order of your code. You're calling screen.exitonclick() before printing "Hi," so the program exits immediately without giving you a chance to see the output.

To fix this, you can reorder your code as follows:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")

print("Hi")

screen = Screen()
screen.exitonclick()

With this change, the output "Hi" should be printed before the program exits.

答案2

得分: 0

如果你想在控制台中看到'Hi'被打印出来,你应该在screen.exitonclick()之前移动print("Hi")语句。程序在你看到'Hi'之前就结束了。所以,像这样:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()

timmy_the_turtle.shape("turtle")

print("Hi")

screen = Screen()
screen.exitonclick()
英文:

If you want to see 'Hi' printed in the console, you should move the
print("Hi") statement before the screen.exitonclick(). The program ends before you get to see the 'Hi' So, like this:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")

print("Hi")

screen = Screen()
screen.exitonclick()

huangapple
  • 本文由 发表于 2023年6月19日 04:15:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502383.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定