Basic Programming Set 3

TOP

Q11. Write a python script to calculate and print Simple Interest?

Q12. Write a python script to take input for two numbers and interchange them (swap them)? (Method :1)(using third variable)

Q13. Write a python script to take input for two numbers and interchange them (swap them)? (Method :2)(without using third variable)

Q14. Write a python script to take input for two numbers and interchange them (swap them)? (Method :3)(Only Python can do it)

 

Q11.

Write a python script to calculate and print Simple Interest?

Sol:

p=float(input("Enter principle  "))
r=float(input("Enter rate "))
t=float(input("Enter time "))
si=(p*r*t)/100
print("SI = ",si)
Go Top

Q12.

Write a python script to take input for two numbers and interchange them (swap them)? (Method :1)(using third variable)

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
print("1st value ",a," 2nd value ",b)
t=a
a=b
b=t
print("1st value ",a," 2nd value ",b)

Go Top

Q13.

Write a python script to take input for two numbers and interchange them (swap them)? (Method :2)(without using third variable)

Sol:

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

Go Top

Q14.

Write a python script to take input for two numbers and interchange them (swap them)? (Method :3)(Only Python can do it)

Sol:

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

Go 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

0051049