victoriagre.blogg.se

Write a pseudocode
Write a pseudocode











write a pseudocode

In our code traces, just like anywhere else, we’ll be careful to make sure that string values are surrounded by quotation marks, and numerical values are not. Notice that the value $6$ in the number variable does not have quotes around it. The next line will use the NUMBER() procedure to convert the text value "6" to the numerical value $6$ and store that in the new number variable: The INPUT() expression will give us that value, which we can store in the text variable as shown in this step: So, if the user enters the text 6, it would look like this in our code trace: In our code trace, we’ll show the user’s input as white text against a black background. On a real computer, the program would pause with a blinking cursor, allowing the user to enter input. The first line will simply print a prompt to the user for input, so we’ll add that to the output section and move to the next line: Let’s quickly trace this program to understand how it works! We’ll set up our code trace like always, as shown below: Let’s look at a quick example of using the INPUT() expression in pseudocode: As we continue to learn more about a real programming language, we’ll see that this same skill applies there as well. However, this allows us to build and reason about programs that require input from the user, which is a useful skill to develop. There isn’t any user interface, and we are acting both as the computer and as the user in most cases. The INPUT() expression can be a bit confusing to work with in pseudocode, since we can only run these programs on our “mental model” of a computer. So, we can use this in an assignment statement to store that value in a variable. Instead, when evaluated the INPUT() expression will simply result in whatever input value is provided from the user. It works just like a procedure, similar to DISPLAY(), but it doesn’t require any parameters. We can use the INPUT() expression in pseudocode to get input from the user. So, let’s introduce a new expression in pseudocode that allows our programs to receive input from the user. This allows programs to truly be interactive and perform work based on what the user needs. While that approach is great for learning the basics, real programs often need to receive data as input from the user. So far, we’ve mainly focused on writing programs that can store and manipulate data, but the data itself has always been included in the code itself.













Write a pseudocode