next up previous
Next: Explanation of the program Up: A Second Python Program: Previous: Pseudocode

The real code

Here is the corresponding Python code. Use your text editor to create the source program. Call the file whoyou.py.

Copy the following lines.

#! /usr/local/bin/python3
name = input("Enter your name ")
age = input("Enter your age ")
print("Your name is", name, "and your age is", age)

Then run your program using

chmod +x whoyou.py
whoyou.py

You should be prompted for your name and age. In each case after typing your response on a single line, you must hit the Enter key to proceed.

It is a good idea to become familiar with Python error messages, so after the script succeeds, try deliberately to make it fail by changing the second age on the last line to ago. Then rerun your program. You should see an error message that tells you the line number where the error occurred, prints the offending line, and explains that the name ago is not defined.

Try running the program, but enter your last name when it asks for your age. What happens?



Carleton DeTar 2017-08-10