Illustration of Input function:
For illustration,
>> rad = input('Enter the radius: ')
Enter the radius: 5
rad = 5
If character or string input is preferred, 's' should be added after the prompt:
>> letter = input('Enter a char: ','s')
Enter a char: g
letter =
g
Note that though this is a string variable, the quotes are not shown. Though, they are shown in the Workspace Window.
If the user enters only spaces or tabs before pressing an Enter key, they are ignored and the empty string is stored in the variable:
>> mychar = input('Enter a character: ', 's')
Enter a character:
mychar =
''
Note that in this case the quotes are shown, to elaborate that there is nothing inside of the string.
Though, if the blank spaces are entered before other characters, they are involved in the string. In this illustration, the user pressed the space bar four times before entering the 'go':
>> mystr = input('Enter a string: ', 's')
Enter a string: go
mystr =
go
>> length(mystr)
ans =
6