Easy Python programs to do when you’re bored

Hmm…..so you are bored and want to try out something exciting. Let’s do some magic with codes!

So, if you like playing with codes, then today we will make a few mini Python programs (trust me, they aren’t hard). The programs are pretty easy, and so are the codes!

What is Python?

Python is a high-level, general-purpose programming language. It was created by Guido Van Rossum. There is a story behind its creation.

He needed a higher-level language in the Amoeba (Operating Systems) project. He realised that the development of administration utilities in C was taking too long while doing them wouldn’t work in the Bourne Shell.

So, to bridge the gap between C and the Bourne Shell, he created Python.

Let’s get started!

Setting Up Python:

If you have Python installed, you can go to the desired environment to run these codes! Even if you haven’t installed it yet, you can take the help of an online Python compiler/interpreter.

Both will show the same results!
You can use Programiz Python Online Compiler, to launch Python straight in your browser!

::Codes::

WRITE A PROGRAM TO TAKE TWO NUMBERS FROM THE USER AND DISPLAY THE SUM OF THEM.

Let me explain how we are going to code this particular program:

First, we will take two variables. A variable is a placeholder that has no defined value and changes according to the case. x and y are the two commonly used variables, but you can choose anything else from a to z, it doesn’t matter (because these have no defined value.). So for this case, we are going to need two numbers.

  • For the first number, we will assign the variable x to it.
  • For the second number, we will assign the variable y to it.

So, now we need to add x and y. For that, we will bring another new variable, called add. This will help display the result.

Finally, we will display the result.

So, let us summarize the entire thing in points:

  • The variable x will be the first number and the user will type the desired number.
  • Next, the variable y will be the second number and again, the user will type the desired number.
  • Now, we bring another variable called add, so it is like add= x+y (Which means if the values for x and y are present, those numbers will be added and its result will be stored in the variable add.)
  • Then, the value stored in the variable add will be displayed to the user.

Well, then let’s start to code this!

Launch either your favourite Python environment on your device (if you’ve already installed it), or just go to Programiz Python Online Compiler to launch it in your browser.

So, this is the code for this particular question. (Copy it yourself and see the magic!)

x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
add= x+y
print("The sum of {0} and {1} is {2}.".format(x, y, add))

Let’s see what the result shows:

Step 1:

Step 2:

Step 3:

It was magical, wasn’t it?


WRITE A PROGRAM TO TAKE TWO NUMBERS FROM THE USER AND DISPLAY THE QUOTIENT AND REMAINDER OF THEM.

Let me explain how we are going to code this particular program:

We will first take two variables. A variable is a placeholder that has no defined value and changes according to the case. x and y are the two commonly used variables, but you can choose anything else from a to z, it doesn’t matter (because these have no defined value.). So for this case, we are going to need two numbers.

  • For the first number, we will assign the variable x to it.
  • For the second number, we will assign the variable y to it.

So, since we need to find quotient and remainder:

  • For finding the quotient, we will assign a variable called quo. The process will be x/y.
  • For finding the remainder, we will assign a variable called rem. The process will be x%y.

So, to summarise it:

  • The variable x will be the first number and the user will type the desired number.
  • Next, the variable y will be the second number and again, the user will type the desired number.
  • Now, we will assign the variable quo for the quotient and rem for the remainder, and the necessary calculations.
  • Then, the value stored in the variables quo and rem will be displayed to the user in the way we formatted.

Well, then let’s start to code this!

So, this is the code for this particular question. (Copy it yourself and see the magic!)

x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
quo= x / y
rem= x % y
print("The quotient of {0} and {1} is {2}.".format(x, y, quo))
print("The remainder of {0} and {1} is {2}.".format(x, y, rem))

Let’s see what the result shows:

So, in total, it first asked for the first number and the second number, found the quotient and the remainder of them and displayed the result in the way we formatted it.


WRITE A PROGRAM TO TAKE A NUMBER FROM THE USER AND DISPLAY THE CUBE OF IT.

Let me explain how we are going to code this particular program:

We will first take a variable. A variable is a placeholder that has no defined value and changes according to the case. x and y are the two commonly used variables, but you can choose anything else from a to z, it doesn’t matter (because these have no defined value.). So for this case, we are going to need two numbers.

  • For this case, we will assign the variable x to it, where the user will type the number which is to be cubed.
  • Then, we will take a variable called cube to it, providing the necessary calculation.

So, to summarise it:

  • The variable x will be the place where the user will type the desired number.
  • The variable cube will be for the calculation.
  • The result will be displayed to the user.

Well, then let’s start to code this!

So, this is the code for this particular question. (Copy it yourself and see the magic!)

x=int(input("Enter the number:"))
cube= pow(x,3)
print("The cube of {0} is {1}".format(x, cube))

Let’s see what the result shows:

So, in total, it first asked for the number, cubed it, and displayed the result in the way we formatted it.


Try a few pieces of Python Codes Yourself!

After so much, I will be giving you a few pieces of code. Copy it yourself and explore the infinite magic!

A program in Python to read two numbers and print their sum and product

a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
sum= a+b
prod= a*b
print("The sum of {0} and {1} is {2}.".format (a, b, sum))
print("The product of {0} and {1} is {2}.".format (a, b, prod))

A program in Python to print the perimeter and area of a rectangle

l=int(input("Enter the length:"))
b=int(input("Enter the breadth:"))
peri= 2*(l+b)
area= l*b
print("The perimeter of this rectangle is {0}.".format (peri))
print("The area of this rectangle is {0}.".format (area))

A program to read a number and check if it is odd or even

x=int(input("Enter the number:"))
if x%2 == 0:
   print(x,"is even.")
else:
   print(x,"is odd.")

A program in Python to read cost price and selling price from the user and prints a message after checking whether there is a profit or loss

cp=int(input("Enter the cost price:"))
sp=int(input("Enter the selling price:"))
if cp>sp:
   loss=cp-sp
   print("The loss is",loss)
else:
   profit=sp-cp
   print("The profit is",profit)

A program in Python to read two numbers and check which one is greater

x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
if x>y:
   print("The larger number is",x)
else:
   print("The larger number is",y)

A program in Python to print the sum of the square of two numbers taken as input by the user

x=int(input("Enter the first number:"))
y=int(input("Enter the second number:"))
one= pow(x,2)
two= pow(y,2)
sum= one+two
print(sum)

A program in Python to read a number and check if it is positive, negative or zero

x=int(input("Enter the number:"))
if x>0:
 print("Positive")
elif x<0:
 print("Negative")
else:
 print("Zero")

A program in Python to input basic information about a user and display it in a paragraph format

name=input("Enter your name:")
age=int(input("Enter your age:"))
print("Your name is",name)
print("Your age is",age)

We hope this helped you learn something new. Visit our Youtube Channel for videos on interesting topics!

Do you like this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

Share This With Others:

Related Posts

2 thoughts on “Easy Python programs to do when you’re bored

  1. I was pretty pleased to discover this great site. I need to to thank you for your time for this particularly fantastic read!! I definitely appreciated every part of it and I have you book marked to see new stuff on your blog.

Leave a Reply

Your email address will not be published.