Can your school quiz show the next player's name without you editing the code?
Your school quiz displays Sam's name next to a score of twelve. Now another player takes a turn. Can you make the same program ask who's playing and display the name they type?
You can use a variable to store a value. The first line stores twelve in score. The second stores the text Sam in name. The last line displays Sam followed by twelve. Run it again and you get the same output.
First, a message on the screen asks for a name. Priya types her name and presses Enter. The program reads her reply and stores it in name. That message asking for a reply is called a prompt.
The program reads the player's reply and stores it in the name variable. This time Alex sees the Name prompt, types Alex and presses Enter. Which text is stored? Pick one answer.
Keep the score at twelve. Next, input shows the Name prompt and waits. Priya types her name and presses Enter. The assignment stores that text in name. Finally, print displays both values. The new output line shows Priya, a space, then twelve.
Dylan types Dylan at the prompt, so name stores Dylan. This time score stores eighteen. The final line calls print with name first and score second. Pick the output from that line.
Compare the print call on the left with the input call and assignment on the right. Both display the Name prompt. On the left, no reply is read. On the right, input reads the reply after you press Enter, and the assignment stores it in name.
A Paper One question could ask you to explain how this program obtains keyboard input and outputs data to the display. Follow the lines in order. Score stores twenty-one. The input function reads the typed name, the assignment stores it in name, and the print function displays both values.