Wednesday, July 15, 2020

Python code: Get input from user and print it with concatenating a string and give comments

Write a program inside the file(with .py as extension) to get input from user and display in screen
Code:
"""
Simple program to get input
to display string with input we got
giving comments
"""
design='---------------------------------------'
info = input("Enter your name:")
print(design + "start" + design)
print('Your name is:', info) #This will print 'Your name is: <<Entered name>>'
print(design , "end" , design)
Were in  this above code, it is explained to

  • write comments, for multiple line comments, we need to start and end with triple double quotes(""")
  • to write single line comments you can start with hash (#)
  • you can assign a string value to variable, like
    • design='---------------------------------------'
    • for assigning string value you can use single quotes or double quotes on both sides as mentioned above
  • to print something we need to use print function
    • print function is a build-in function in python to print values
    • We can directly print string values using single quotes or double quotes
      • print("Welcome")
      • print('Welcome')
    • Concatenate string with a variable
      • Assume that string John is stored on a variable called variablename now if we need to print Welcome John means
        • print("Welcome",variablename) #Output will be Welcome John, an automatic space will be there if we use comma
        • if we don't need space means print("Welcome"+John)
      • While concatenating using +
        • string + string #correct
        • string + int #wrong
        • int + int #correct
    • Getting input
      • We need to use input() function to get input from user
You can see the below video for better understanding of this post



In next post we can see about using numbers and calculations

No comments:

Post a Comment

Conditional Statement if, if and else, if and elif with else using Arithmetic Operators and Logical Operators in python3

 If you are new to coding means conditional statement will be unfamiliar to you. For that we can take a real-time example for understanding ...