Another look at python’s input and output
Here, we go into a little more detail about data input and output mechanisms, as these topics are so important in the design of a simulator because formatting data is all-important to the interpretation of the data.
Let’s have another look at input in Python. Inputting data from the keyboard is very easy. To input text, you write x = input()
and that’s it. When this statement is encountered, Python waits for your input. You enter the text and terminate it with a return (Enter key). If you just enter a return without text, the value of x
will be a null string – that is, ' '. The data you input is stored in text form.
Python lets you display a prompt before receiving the input; for example, you can write the following:
x = input('Please enter your age')
Because the input is in character form, you must convert numeric values into integer form before using them. It’s easy to perform...