0% found this document useful (0 votes)
5 views3 pages

Python Programs for Basic Calculations

Uploaded by

futurexvishal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Programs for Basic Calculations

Uploaded by

futurexvishal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Program 1: Take user input for name, age, course and print details

name = input('Enter your name: ')


age = int(input('Enter your age: '))
course = input('Enter your course: ')
print('Name:', name)
print('Age:', age)
print('Course:', course)

# Program 2: Check even or odd numbers

num = int(input('Enter a number: '))


if num % 2 == 0:
print('Even number')
else:
print('Odd number')

# Program 3: Simple Interest

p = float(input("Enter principal amount: "))


r = float(input("Enter rate of interest: "))
t = float(input("Enter time in years: "))

si = (p * r * t) / 100

print("Simple Interest =", si)

# Program 4: Compound Interest

p = float(input('Enter principal amount: '))


r = float(input('Enter rate of interest: '))
t = float(input('Enter time in years: '))
ci = p * (1 + r/100) ** t - p
print('Compound Interest =', ci)
# Program 5: Swap two variables

a = int(input('Enter first number: '))


b = int(input('Enter second number: '))
print('Before swapping: a =', a, 'b =', b)
temp = a
a=b
b = temp
print('After swapping: a =', a, 'b =', b)

# Program 6: Fibonacci Series

n = int(input('Enter terms: '))


a, b = 0, 1
print('Fibonacci Series:')
for i in range(n):
print(a)
c=a+b
a=b
b=c

# Program 7: Square Root

import math
num = float(input('Enter any number: '))
print('Square Root =', [Link](num))

# Program 8: Add 3 numbers

x = int(input('Enter first number: '))


y = int(input('Enter Second number: '))
z = int(input('Enter Third number: '))
sum = x + y + z
print('Sum =', sum)
# Program 9: Operations of two numbers

n1 = float(input('Enter first number: '))


n2 = float(input('Enter second number: '))
print('Addition =', n1 + n2)
print('Subtraction =', n1 - n2)
print('Multiplication =', n1 * n2)
print('Division =', n1 / n2)

# Program 10: Profit and Loss

cp = float(input('Cost Price (CP) dale: '))


sp = float(input('Selling Price (SP) dale: '))
if sp > cp:
print('Profit =', sp - cp)
elif cp > sp:
print('Loss =', cp - sp)
else:
print('No Profit No Loss')

You might also like