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

Sunday, July 12, 2020

Run a simple python code in windows machine

Run python in windows machine

You can download python3 for windows from the below mentioned site



Download and install it, then open the command prompt and type python


After  typing python and clicking enter, you will get into the python shell.

Now you can write a print statement to run a basic python program after ">>>"




This line is used to print the message "This is the first python program"

print is a function in python to display message. the message can be inside single quotes or double quotes

>>> print('This is the first python program')

                          (OR)

>>> print("This is the first python program")

both are correct

In next post we can see about getting input and printing that with a static message. 

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 ...