0% found this document useful (0 votes)
44 views4 pages

Python Math Projects for Beginners

The document contains 4 problem statements and their solutions to calculate various mathematical calculations using Python programs that take input from the user. Each program calculates things like total marks and percentage of a student, mathematical operations on two numbers, perimeter and area of a square, and circumference and area of a circle. The programs take input, perform the relevant calculations, and output the results.

Uploaded by

Moomal
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)
44 views4 pages

Python Math Projects for Beginners

The document contains 4 problem statements and their solutions to calculate various mathematical calculations using Python programs that take input from the user. Each program calculates things like total marks and percentage of a student, mathematical operations on two numbers, perimeter and area of a square, and circumference and area of a circle. The programs take input, perform the relevant calculations, and output the results.

Uploaded by

Moomal
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

Problem Statement 1:

Create a python program to enter the Name, Roll No. and Marks for 4 subjects and calculate the total
marks and percentage. Use the input Statement for the same.

Program:

name= input("Enter the name of the student:")


roll= int(input("Enter the roll no:"))

english= int(input("Enter the marks for english:"))


maths= int(input("Enter the marks for maths:"))
science= int(input("Enter the marks for science:"))
ict= int(input("Enter the marks for ict:"))

percent= (float)(english+maths+science+ict)/400*100

print("The name of the student is:" , name)


print("The roll no =. of the student is:" , roll)
print("The marks for english are:" , english)
print("The marks for maths are:" , maths)
print("The marks for science are:" , science)
print("The marks for ict are:" , ict)

print("The percentage obtained is:" , percent)

Output:

Enter the name of the student: Amairaa


Enter the roll no: 27
Enter the marks for english: 70
Enter the marks for maths: 85
Enter the marks for science: 90
Enter the marks for ict: 75
The name of the student is: Amairaa
The roll no =. of the student is: 27
The marks for english are: 70
The marks for maths are: 85
The marks for science are: 90
The marks for ict are: 75
The percentage obtained is: 80.0
Problem Statement 2:
Create a python program to enter two numbers and calculate Addition, Subtraction, Multiplication and
Division on the same.

Program:

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


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

sum = num1+num2
sub = num1-num2
mult= num1*num2
div= (float)(num1/num2)

print("The sum of two numbers is:" , sum)


print("The subtraction of two numbers is:" , sub)
print("The multiplication of two numbers is:" , mult)
print("The division of two numbers is:" , div)

Output:

Enter the first number: 93


Enter the second number: 26
The sum of two numbers is: 119
The subtraction of two numbers is: 67
The multiplication of two numbers is: 2418
The division of two numbers is: 3.576923076923077
Problem Statement 3:
Create a python program to calculate the perimeter and area of Square using the input() function.

Program:

side= int(input("Enter the value for side of the square:"))

perimeter= 4*side
area= side*side

print("The area of the square is:" , area)


print("The perimeter of the square is:" , perimeter)

Output:

Enter the value for side of the square: 6


The area of the square is: 36
The perimeter of the square is: 24
Problem Statement 4:
Create a python program to calculate the circumference and area of a circle using the input() function.

Program:

radius= float(input("Enter the radius:"))

area= (float)(3.14*radius*radius)
circum= (float)(2*3.14*radius)

print("The area of the circle is:" , area)


print("The circumference of the circle is:" , circum)

Output:

Enter the radius:10.5


The area of the circle is: 346.185
The circumference of the circle is: 65.94

Common questions

Powered by AI

Each program follows a straightforward linear logic: first, take user input using input() where appropriate; second, perform the necessary calculations specific to the context (e.g., arithmetic operations in Source 2, geometric formulas in Sources 3 and 4); third, output the calculated values. Error handling is not explicitly covered, indicating a reliance on correct user input for successful execution .

Lack of input validation means the programs assume all inputs are correct and expected types, leading to potential runtime errors (e.g., ValueError for non-integer inputs) and logical errors (e.g., incorrect calculations on erroneous data). This could cause crashes or incorrect outputs without user-friendly error messages guiding corrections .

Both programs use formulas to calculate dimensions based on user input. For a square, the perimeter is calculated by 4 * side and the area by side * side, leveraging the equal side lengths. For a circle, the circumference and area are calculated using the radius, with perimeter = 2 * π * radius and area = π * radius^2. The circle program utilizes a floating-point constant for π to handle more precise calculations compared to integer operations for the square .

Implementing modular programming by decomposing the arithmetic operations into individual functions (add, subtract, multiply, divide) can improve clarity, reuse, and manageability. It allows for each operation to be tested and debugged separately, enhances readability and debugging, and makes extending functionality easier (e.g., new operations).

The precision of π (3.14 used in the program) directly affects the calculations of a circle's area and circumference, as a more precise value like 3.1415926535 would result in more accurate outcomes. Alternatives include using Python's math library, which provides π as math.pi for higher precision and more reliable scientific calculations .

The program would be insufficient if additional subjects or variable total possible marks were introduced, as it assumes a fixed input size and total of 400 marks. Additionally, it lacks error handling for inputs, assumes integer inputs, and doesn't address extra credit or weightage that some educational systems incorporate .

The calculation uses a float cast to ensure that operations involving division (to find the percentage) are processed in floating-point to maintain precision, which prevents unintentional integer division that could lose accuracy. Dividing integers leads to floating-point results in Python 3, yet explicitly casting reinforces this behavior .

Using float typecasting ensures that division operations produce floating-point results, allowing for fractional outcomes rather than rounded down integers, which is essential for accuracy when dividing numbers not evenly divisible, such as 93/26 = 3.576923076923077 .

The program reads input for the student's name, roll number, and marks for four subjects: English, Maths, Science, and ICT. It calculates the total marks by summing the individual subject scores and calculates the percentage by dividing the total marks by 400 and multiplying by 100. This is done with the formula percent = (float)(english + maths + science + ict) / 400 * 100 .

If a non-integer value is input for the roll number or marks, the program will raise a ValueError since it attempts to convert the input value to an integer using int(input()), which only accepts valid integer literals .

You might also like