Question: For this question, you will write a program in python that allows the user to type in a number on the keyboard. When the user
For this question, you will write a program in python that allows the user to type in a number on the keyboard. When the user clicks the mouse, the program will calculate and display the square of the number that was typed in eg if the user types in the number then when the mouse is clicked, your program will display the value ie Your program should use ModelViewController design.
Heres the trick, though; Processing doesnt have any automatic way of letting the user type in a multidigit number. It only detects each individual keypress as it happens. So well have to use a string variable to keep track of all the digits that have been typed in so far. When the mouse is clicked, well need to convert our string of digits into a number an integer and display the square of that number.
Your program should behave as follows:
When the program starts: The program simply displays a blank, black canvas.
When the user presses a key: Add any key that the user types to your string of digits. If the user presses a key that is not a digit, its okay if your program crashes adding errorchecking is beyond the scope of this question Always display the current digits that the user has typed in using the text function.
When the user clicks the mouse: Convert the digits that have been typed in to an integer and display on the canvas the square of that integer. Then, make sure to reset the digit string variable to the empty string so that the user can later type in a different number.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
