0% found this document useful (0 votes)
2 views7 pages

Python Programs for Basic Calculations

Uploaded by

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

Python Programs for Basic Calculations

Uploaded by

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

Assignment: Write a program to find the sum of any two numbers

Program Code:
# Program to find the sum of two numbers

# Get first number from user

num1 = float(input("Enter the first number: "))

# Get second number from user

num2 = float(input("Enter the second number: "))

# Calculate the sum

sum_result = num1 + num2

# Display the sum

print("The sum of", num1, "and", num2, "is:", sum_result)

Sample Output:

Enter the first number: 5

Enter the second number: 3

The sum of 5.0 and 3.0 is: 8.0


Assignment: Write a program to print personal information like name,
fathers name, class & school name

Program Code:
# Program to collect and display student personal information

# Get student's name (allows spaces)

name = input("Enter your name: ")

# Get father's name (allows spaces)

father_name = input("Enter your father's name: ")

# Get class (e.g., 9, 10,12)

class_name = input("Enter your class: ")

# Get school name (allows spaces)

school_name = input("Enter your school name: ")

# Print all information

print("Student Details:")

print("Name:", name)

print("Father's Name:", father_name)

print("Class:", class_name)

print("School:", school_name)

Sample Output:
Enter your name: Vihaan Chorera

Enter your father's name: Anshuman

Enter your class: 9D

Enter your school name: Elpro International School

Student Details:

Name: Vihaan Chorera

Father's Name: Anshuman

Class: 9D

School: Elpro International School


Assignment : Write a program to find the square of a number

# Program to calculate square of a number

# Get integer number from user

number = int(input("Enter an integer number: "))

# Calculate square

square = number * number

# Print the result

print("Square of", number, "is:", square)

Enter an integer number: 17

Square of 17 is: 289


Assignment : Write a program to covert kilometers to meters

# Program to convert kilometers to meters

# Get kilometers from user

kilometers = float(input("Enter distance in kilometers: "))

# Convert to meters (1 km = 1000 meters)

meters = kilometers * 1000

# Print the result

print(kilometers, "kilometers =", meters, "meters")

Enter distance in kilometers: 25.5

25.5 kilometers = 25500.0 meters


Assignment : Write a program to print a table of any input number

# Program to print times table (multiplication table) of a number

# Get integer number from user

number = int(input("Enter a number for times table: "))

# Print times table from 1 to 10

print("Times Table of", number)

print("-" * 20)

for i in range(1, 11):

result = number * i

print(number, "x", i, "=", result)

Enter a number for times table: 17

Times Table of 17

--------------------

17 x 1 = 17

17 x 2 = 34

17 x 3 = 51

17 x 4 = 68

17 x 5 = 85

17 x 6 = 102

17 x 7 = 119

17 x 8 = 136

17 x 9 = 153

17 x 10 = 170
Assignment: Write a rpgram to calculate simple interest

# Program to calculate Simple Interest

# Get principal amount from user

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

# Get rate of interest from user (in percentage)

rate = float(input("Enter annual rate of interest (%): "))

# Get time in years from user

time = float(input("Enter time in years: "))

# Calculate simple interest: SI = (P * R * T) / 100

simple_interest = (principal * rate * time) / 100

# Print the result

print("Simple Interest =", simple_interest)

Enter principal amount: 12500

Enter annual rate of interest (%): 7.5

Enter time in years: 8

Simple Interest = 7500.0

You might also like