Introduction

Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985-1990.

python-logo

Python has fewer syntactical constructions than other languages. Python is designed to be highly readable. It uses English keywords frequently whereas the other languages use punctuations.

In this Blog, we will be studying Python version 3 programming language. In each blog post, we will have a simple problem statement/title explaining what is the purpose of the given assignment. I will be adding comments in the assignments along with the number of reference links so that it will be easy for you all to understand the purpose of the code statements. You may add comments if you have any queries regarding the assignment. I hope you will enjoy studying python 3 with me. Thank you!

 

Arithmetic Operations (Version 2: with user input from keyboard)

In the previous blog post Arithmetic Operations (Version 1 : with default input), we used default input parameters for all the arithmetic operations. Now we will be using the input from user.


# Assignment No. 4
# Simple Arithmetic Operations with user input
# Title: Simple Arithmetic Operations: addition, subtraction,
# multiplication and division performed on the input given by user.

print ("Enter first number \n")
num1= input()
print ("Enter second number \n")
num2= input()

print("\n This Program shows Simple Arithmetic Operations")

print (" \n Addition is:")
print(int(num1)+int(num2))

print (" \n Subtraction is:")
print(int(num1)-int(num2))

print (" \n Multiplication is:")
print(int(num1)*int(num2))

print (" \n Division is:")
print(int(num1)/int(num2))

print (" \n Remainder is:")
print(int(num1)%int(num2))

print (" \n Quotient is:")
print(int(num1)//int(num2))

print ("\n Exponential operation is: ")
print(int(num1)**int(num2))


Output:

Enter first number
5

Enter second number
4

This Program shows Simple Arithmetic Operations

Addition is:
9

Subtraction is:
1

Multiplication is:
20

Division is:
1.25

Remainder is:
1

Quotient is:
1

Exponential operation is:
625

Process finished with exit code 0


Functions used:

1. print ()

We have used a print () function which prints whatever we type inside parentheses. Computer just ignores whatever we put inside the parentheses and prints the string in the console.

2. input ()

When the input() function is called, the program flow will be stopped until the user has given an input. The input() function accepts the user input.


Note:

#  is used for inserting comments

\n  is used to insert newline


 

Accepting user input from keyboard

In Python 3.0, we can use input() function to read data from the user. We can store the input from user into a variable.


# Assignment No. 3
# Title: Accepting user input from keyboard

print ("\n Enter a number")
num1= input()

print (" You have entered ")
print (num1)   
# a number entered by user is stored in variable num1 

name= Input ("Enter your name: ")

print ("Your name is ")
print (name)

# name entered by user is stored in variable name

Output: 

 Enter a number
 4

 You have entered 
 4

 Enter your name: Learnerdb

 Your name is 
 Learnerdb

Process finished with exit code 0


Functions used:

1. print ()

We have used a print () function which prints whatever we type inside parentheses. Computer just ignores whatever we put inside the parentheses and prints the string in the console.

2. input ()

When the input() function is called, the program flow will be stopped until the user has given an input.


Note:

#  is used for inserting comments

\n  is used to insert newline


 

 

Arithmetic Operations (Version 1: with default input)

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication etc.

This is basic python program which performs basic arithmetic operations on two numbers.

 

  • Addition operation using + operator.
  • Subtraction operation using - operator.
  • Multiplication operation using * operator.
  • Division operation using / operator, num1 / num2 divides left hand operand by right hand operand.
  • Floor Division operation using // operator, num1 // num2 divides left hand operand by right hand operand, here it removes the values after decimal point.
  • Modulus % operator when applied returns the remainder when left hand operand is divided by right hand operand num1 % num2.
  • Exponential operation using ** operator, num1 ** num2 returns value of num1 raised to num2.

And here is the Assignment No. 2

# Assignment No. 2
# Simple A­rithmetic Operations with Default input numbers
# Title: Simple Arithmetic Operations: Addition, Subtraction,
# Multiplication and Division.

print("\n This Program shows Simple Arithmetic Operations")
print(" \n Addition is:")
print(22 + 3)
print(" \n Subtraction is:")
print(16 - 2)
print(" \n Multiplication is:")
print(9 * 20)
print(" \n Division  is:")
print(17 / 2)
print(" \n Quotient is:")
print(17 // 2)
print(" \n Remainder   is:")
print(17 % 2)
print ("\n Exponential operation is: ")
print (2**4)


Output:

This Program shows Simple Arithmetic Operations

Addition is:
25

Subtraction is:
14

Multiplication is:
180

Division is:
8.5

Quotient is:
8

Remainder is:
1

Exponential operation is: 
16


Functions used:

1. print ()

We have used a print () function which prints whatever we type inside parentheses. Computer just ignores whatever we put inside the parentheses and prints the string in the console.


Note:

#  is used for inserting comments

\n  is used to insert newline


 

Download and Install Python 3.0

In order to use Python, it must be first installed on your computer. Follow these steps:


Download Python 3.0 here:

https://www.python.org/downloads/


PyCharm: Python IDE for Professional Developers by JetBrains is an Integrated Development Environment (IDE) used in computer programming, specifically for the Python language.

PyCharm is the best IDLE I’ve ever used. I would suggest you to download PyCharm Community Edition. It is totally free and open-source.

Download PyCharm Community Edition here :

https://www.jetbrains.com/pycharm/download/#section=windows


 

Hello World!

Hello World!

The “Hello, World!” program is a classic and time-honored tradition in computer programming.

We are going to write our very first program in Python 3 which prints a simple “Hello World!” text on the python console.


# Assignment No. 1
# Title: Print "Hello World!" on Python console

print ("Hello World!")

Output:

Hello World!
Process finished with exit code 0

Functions used:

1. print ()

We have used a print () function which prints whatever we type inside parentheses. Computer just ignores whatever we put inside the parentheses and prints the string in the console.

Note: # is used to insert comments inside program.


Congratulations! You have just completed first Python Assignment! 🙂