英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论