Is there a way to see what the input() function is doing?

so im trying to write a solution to the “Simplified Monopoly™ Turns Prediction” problem, but im having trouble understanding what the input() function is doing.

in python 3, the standard code looks like:
p = int(input())
for i in range( p ):
player = input()
d = int(input())
for i in range(d):
dice = input()
for i in range(40):
boardline = input()

now this is confusing for example, because the player variable now only contains a single player name, and no value for its starting position.

i tried to do basic debugging steps to figure out whats happening with the input, by printing out the input() function without an input, iterating over the input() function, and trying to call different values with the input() function. All of which result in a single output.

How are newbies handling these sorts of input functions when the input values is a large list of different types and values and we cant see what the function is doing? How do we access the parts we want at specific times?

Im basically stuck at the point of just trying to access a single players start location and the relevent dice rolls for that player, but even if i could get those values, how do i then extract the next player from the input() function?

You’re supposed to store these inputs yourself.
You can for example create lists before the inputs and append into them.
A cleaner way in Python is to use list comprehension:
D = [int(input()) for _ in range(d)]

1 Like

The ultimate guide should be in the statement.

Input

Line 1: An integer P for the number of players
Next P lines: One line for each player, containing the name and the initial position, separated with a space
Next line: An integer D for the number of dice rolls in playing order
Next D lines: One line for each dice roll (space-separated)
Next 40 lines: One line for the name of each board position. Note that these aren’t actually needed to solve the puzzle.

You are told that each “P line” contains one name, one space, and one position.
The template code gives you a string. You should break it down, by your own code, into two values for your own use.

The default input template code is just a convenient quick start. You can, and many coders do, delete them and rewrite the input code in their own preferred styles.

1 Like