Input statement in Python and comments
Subject: Python Programming
Comment in Python
As you write more lines of code, it would be easy for you to forget what some lines of code you have writtenare doing.
It's a best practice for you to add a note or comment to inform you or another programmer who may need to maintain the code in future.
Comments are non executable line you add to you program to inform you or another programmer what you want the code to do.
Single line comment is done with # sign
For example
#ask a user to enter his or her name
name=input("Enter your name please ")
#display a message with the user name
print ("Welcome ",name)
Note: any text after the # sign will not be execute, because it's a comment.
Input Statement
The input statement is use to collected data or information from a user when you run your Python code, this makes your program to be more interactive and useful.
By default the input statement collect data as a string or text, therefore if you are to collect a number, you will need to convert the input to integer or float.
For example:
age=int(input("How hold are you "))
score1=float(input("Enter your first score "))
score2=float(input("Enter your second score "))
result=score1+score2
print ("You are ",age," years old and your total score is ",result)
By:
Benjamin Onuorah
Login to comment or ask question on this topic
Previous Topic Next Topic