Python Input Program

How to create a python program that gets string input from the user

This is a Python 3 tutorial for creating an Input Program, and in order to get started I always start with a comment about what the program that I am building is. By using the # key you are able to then create comments in Python.

# program that gets input from the user.
# get user's input and greet the user with the input they selected

After the comment, I would usually then import the functions that I would utilize within the program. In this program, I did not use a function, so I did not have to import anything for this program.\

Next, I will greet the user with a print statement telling the user what the program does and after that, I will then get input from the user to input their name as well as their nickname in order to provide them with a simple acknowledgment. 

print("Hello There! This program will greet you")
name = input("Enter your name: ")
nickname = input("Please enter your nickname: ")

After I have gotten the input from the user in this program, I just provide the user with a simple print statement to acknowledge them.

print("Hello " + name + " its nice to meet you! and great nickname")
print(nickname + " Wow! that's awesome!")

No comments:

Post a Comment

Best Devices To Get Started With Programming

Having a good solid computer is vital to start coding, and HP offers solid laptops for coders at every level.