Python Programming Set 1

  • Some very basic but important programs which will make the student familiar with python script mode programming.
  • Programs related to taking input for numeric values and performing calculations

Top

Q1. Write a python script to take input for two numbers calculate and print their sum?

Q2. Write a python script to take input for a number calculate and print its square?

Q3. Write a python script to take input for a number, calculate and print its cube?

Q4. Write a python script to take input for two numbers, calculate and print their difference?

Q5. Write a python script to take input for three numbers,  calculate and print their product?

Solutions

Q1.

Write a python script to take input for two numbers calculate and print their sum?

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
s=a+b
print("1st no = ",a)
print("2nd no = ",b)
print("Sum = ",s)

Go Top

Q2.

Write a python script to take input for a number calculate and print its square?

Sol:

a=int(input("Enter any no "))
b=a*a
print("Number ",a)
print("Square ",b)

Go Top

Q3.

Write a python script to take input for a number calculate and print its cube?

Sol:

a=int(input("Enter any no "))
b=a*a*a
print("Number ",a)
print("Cube ",b)

Go Top

Q4.

Write a python script to take input for two numbers to calculate and print their difference?

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
d=a-b
print("1st no = ",a)
print("2nd no = ",b)
print("Difference = ",d)

Go Top

Q5.

Write a python script to take input for three numbers calculate and print their product?

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
p=a*b*c
print("1st no = ",a)
print("2nd no = ",b)
print("3rd no = ",c)
print("Product = ",p)

Go To Top

Python Basic Programming Tutorial

Python Introduction     Getting started in Python Programming      Python propgramming fundamentals     Python Operators    Python If Condition     Python for loop    Python range construct      Python While loop    break and continue statements     Different looping techniques     Python List     Python String     Python Functions    Python Inbuilt Functions     Python Recursion     Using Python Library     Python Tuples     Python Dictionary     Python Sets     Python Strings     Python Exception Handling     Python Data File Handling

Visitor Counter

0056742