Due: Thursday, September 9th at class time
In this prelab you'll get further acquainted with basic input and create one program to read in strings from the user and print a greeting.
In Python, we have a built-in function for retrieving input from the user.
input(): This function retrieves a sequence of keystrokes from the user up to the point where the user types the Return/Enter key. This sequence of characters is returned as a string as the value returned by the function. We typically take the value returned and assign it to a variable. Note that this function _both_ performs input, because it is getting the keystroke sequence from the user, and this is _outside_ the program; _and_ this function returns a value because the string result is returned as the value of the function.
Every time we retrieve input from the user, we are getting a string, because typing on the keyboard generates our sequence of characters. Once the string is "in" the program, we may want to interpret that string as a different data type, like an integer (int) or a real-valued number (float). We accomplish this by invoking a function whose purpose is to take a string as a parameter and to convert the string to the data type given by the name of the function. So we use the int() function to convert a string to an integer, and the float() function to convert a string to a float.
We first are going to practice using input() and the type conversion functions by using the Python Shell interpreter. If you bring up the Wing IDE and click the "Options" drop-down in the upper right corner, you will see a "Save a Copy" menu item. Don't click on this now, but this will enable us to get a text file with the set of interactions from the Python Shell window, so that you can show me that you completed this practice part.
For each of the following, you will type in the given input() invocations with their assignment statement, and then, as the user, type the indicated input sequence of characters in bold. We use assignment statements so that we can associate the variable testvar with the function invocation resultant value and can see both the value and the type. So after each input statement, I want you to predict the value and the type of testvar, and then to type in
>>> testvar
to see the value, and
>>> type(testvar)
to see its type.
In some cases, you may get an error. Try to predict this error and/or explain why it occurred.
Save your Python Shell interaction by using the Options meny and selecting "Save a Copy", putting it in a file named 'inputRun.txt' and put it in your Prelab02 folder for submission.
Create a program called Greetings.py that consists of a definition of a main() function followed by its invocation. The main() function should ask the user to enter their name, and then enter their nickname, and then prints "Welcome, <their name>, (or should I say <nickname>)!"
In your assignment dropbox create a folder called Prelab02. Into this folder place: