import turtle # creating the turtle screen screen = turtle.Screen() # prompting the user to enter a number and storing it in a variable number = screen.numinput("Enter a number", "Please enter a number:") # displaying the number on the screen turtle.write("The number entered is " + str(number), align="center", font=("Arial", 16, "normal")) # closing the screen turtle.done()
import turtle # creating the turtle screen screen = turtle.Screen() # prompting the user to enter two numbers and storing them in variables num1 = screen.numinput("Enter first number", "Please enter the first number:") num2 = screen.numinput("Enter second number", "Please enter the second number:") # calculating the sum of the two numbers and displaying it on the screen sum = num1 + num2 turtle.write("The sum of the two numbers is " + str(sum), align="center", font=("Arial", 16, "normal")) # closing the screen turtle.done()In this example, the user is prompted to enter two numbers and the sum of the two numbers is calculated and displayed on the turtle canvas. Package library: turtle