0% found this document useful (0 votes)
11 views6 pages

Python Basic Arithmetic and Functions

The document contains a Python assignment with various programming tasks including basic arithmetic operations, calculating simple interest, finding the area of geometric shapes, temperature conversion, and handling user input. Each task is accompanied by example outputs demonstrating the expected results. The assignment covers fundamental programming concepts such as variables, input/output, and control structures.

Uploaded by

vani.gera2008
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)
11 views6 pages

Python Basic Arithmetic and Functions

The document contains a Python assignment with various programming tasks including basic arithmetic operations, calculating simple interest, finding the area of geometric shapes, temperature conversion, and handling user input. Each task is accompanied by example outputs demonstrating the expected results. The assignment covers fundamental programming concepts such as variables, input/output, and control structures.

Uploaded by

vani.gera2008
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

Python Assignment 1

Ans 1.
a=int(input('Enter the first no.'))
b=int(input('Enter the second no.'))
c=a+b

print('The sum of the given nos. = ',c)


d=a-b
print('The difference of the given nos. = ',d)
e=a*b
print('The product of the given nos. = ',e)

f=a/b
print('The quotient when the given nos. are divided = ',f)
g=a%b
print('The remainder when the given nos. are divided = ',g)
h=a//b

print('The integer quotient when the given nos. are divided = ',h)
OUTPUT
Enter the first no. 5
Enter the second no.6
The sum of the given nos. = 11

The difference of the given nos. = -1


The product of the given nos. = 30
The quotient when the given nos. are divided = 0.8333333333333334
The remainder when the given nos. are divided = 5
The integer quotient when the given nos. are divided = 0

Ans 2.
p = float(input("Enter the principal amount: "))
r = float(input("Enter the rate of interest (in %): "))
t = float(input("Enter the time (in years): "))
s=(p*r*t)/100
print('Simple Interest = ',s)
OUTPUT

Enter the principal amount: 1000


Enter the rate of interest (in %): 5
Enter the time (in years): 2
Simple Interest = 100.0
Ans 3.

l=float(input("Enter the length: "))


b=float(input("Enter the breadth: "))
area=l*b
print('The area of the rectangle = ',area)
OUTPUT

Enter the length: 10


Enter the breadth: 4
The area of the rectangle = 40.0
Ans 4.
a=float(input("Enter the first side: "))

b=float(input("Enter the second side: "))


c=float(input("Enter the third side: "))
s=(a+b+c)/2
a=(s*(s-a)*(s-b)*(s-c))**1/2
print('The area of the triangle = ',a)

OUTPUT
Enter the first side: 5
Enter the second side: 7
Enter the third side: 10
The area of the triangle = 132.0
Ans 5.
a=float(input("Enter the temperature in Fahrenheit: "))
b=(a-32)*5/9
print('The temperature in Celcius = ',b)

OUTPUT
Enter the temperature in Fahrenheit: 98
The temperature in Celcius = 36.666666666666664
Ans 6.
a=int(input('Enter the time (in minutes): '))

h=a//60
m=a%60
print('Time: ',h,'hours and',m,'minutes')
OUTPUT
Enter the time (in minutes): 90

Time: 1 hours and 30 minutes


Ans 7.
a=float(input('Enter the height (in inches): '))
f=a//12
i=a%12

print('Height: ',f, 'feet and',i, 'inches')


OUTPUT
Enter the height (in inches): 70
Height: 5.0 feet and 10.0 inches
Ans 8.

a=int(input("Enter a no."))
b=int(input("Enter a no."))
print(id(a))
print(id(b))
c=a
a=b
b=c
print(id(a))
print(id(b))

OUTPUT
Enter a no.7
Enter a no.8
140729610095224
140729610095256

140729610095256
140729610095224
Ans 9.
a=int(input('Enter a no.'))
a=b=c

print(id(a))
print(id(b))
print(id(c))
OUTPUT
Enter a no.10

140729610095224
140729610095224
140729610095224
Ans 10.
a=input('Write any sentence: ')

print(a,'#')
OUTPUT
Write any sentence: You are pretty
You are pretty #
Ans 11.
a=int(input('Enter mathematics mark: '))
b=int(input('Enter english mark: '))
c=int(input('Enter science mark: '))
d=int(input('Enter social studies mark: '))

e=int(input('Enter sanskrit mark: '))


print('Mathematics = ',a,' English = ',b,' Science = ',c,' Social Studies = ',d,' Sanskrit = ',e)
OUTPUT
Enter mathematics mark: 99
Enter english mark: 98

Enter science mark: 97


Enter social studies mark: 100
Enter sanskrit mark: 98
Mathematics = 99 English = 98 Science = 97 Social Studies = 100 Sanskrit = 98
Ans 12.

x="""a)"The professor said,"Please don't sleep in the class.'" """


y="""#b)"Opportunities don't happen. You create them." Try not to become a person of
"success" but try to become a person of "value" """
print(x)
print(y)
OUTPUT
a)"The professor said,"Please don't sleep in the class.'"

#b)"Opportunities don't happen. You create them." Try not to become a person of "success"
but try to become a person of "value"
Ans 13.
a=input('Enter you name: ')
b=int(input('Enter no. of times you want the name to repeat: '))
print(a*b)

OUTPUT
Enter you name: Vani
Enter no. of times you want the name to repeat: 6
VaniVaniVaniVaniVaniVani
Ans 14.
a=input('Enter you first subject: ')
b=input('Enter you second subject: ')

c=input('Enter you third subject: ')


d=input('Enter you fourth subject: ')
e=input('Enter you fifth subject: ')
print(a,'*',b,'*',c,'*',d,'*',e)
OUTPUT

Enter you first subject: English


Enter you second subject: Maths
Enter you third subject: Physics
Enter you fourth subject: Chemistry
Enter you fifth subject: Computer Science

English * Maths * Physics * Chemistry * Computer Science

Common questions

Powered by AI

Designing a Python program that prints marks for multiple subjects involves considerations such as input validation to ensure correctness and handling various data types reliably. The program should also display outputs in a user-friendly format and possibly perform additional calculations, like average or total marks. Careful structuring of user prompts and clarity in output presentation are key to enhancing usability, along with possible integrations of storage capabilities for tracking and comparing marks over time, important in educational settings for assessing student progress .

Input validation is crucial in these examples to ensure that the inputs provided are valid numbers, which is necessary for the correct calculation of simple interest and area. Without validating input, incorrect or unexpected inputs could lead to runtime errors or incorrect outputs, potentially misleading users about financial or geometrical calculations. This validation becomes especially important in practical applications involving financial data or precise measurements .

Exercises involving manual conversion of units, like minutes to hours or inches to feet, offer several educational benefits, including reinforcing understanding of measurement units and practicing arithmetic operations. These exercises foster computational thinking by encouraging students to consider conversion factors and apply logical reasoning to solve problems. Additionally, they build foundational knowledge critical for STEM fields by linking mathematical concepts to real-world applications, helping learners grasp the significance of accurate measurements .

Using mathematical operators in Python like +, -, *, /, %, and // allows for quick and efficient calculations by leveraging the interpreter's optimized handling of arithmetic operations. This not only reduces manual computation errors but also executes complex arithmetic operations with high precision and speed. This is evident from the provided Python assignments which perform multiple arithmetic operations efficiently using basic input and output functions .

The sequence of instructions in simple interest calculation mainly affects execution efficiency and comprehension clarity rather than computational accuracy directly, assuming all inputs are correct. By structuring calculations to minimize complexity and operator errors, such as performing division last, sequential instructions can reduce cumulative computational error in large datasets. Proper sequence allows for validation checkpoints and ensures each operation builds accurately on the last, which is crucial for maintaining accuracy in real-world financial computations that require precise interest calculations over large sums or periods .

Using identical identifiers, as seen in the provided variable swapping script where 'c=a', can be problematic if not managed properly. Identical identifiers lead to overwriting values quickly, resulting in loss of data if a mistake is made. The id function examples highlight the swapping without a temporary variable, which may lead to confusion in larger, more complex scripts. The approach may also introduce memory management issues or unexpected behavior in concurrent programming scenarios where identifier scope and lifecycle are critical .

Enhancing the Fahrenheit to Celsius conversion can be achieved by incorporating input validation to handle unexpected values, such as extremely high temperatures, and by rounding the results to a specified number of decimal places for consistency. Further improvements could include providing informative error messages for invalid inputs and allowing temperature inputs in various formats (e.g., integers and floats). Additionally, implementing a loop for multiple conversions without restarting the program would improve usability .

Heron's formula is beneficial for calculating the area of a triangle because it only requires the lengths of the three sides, making it versatile for any type of triangle without needing additional height information. This allows for simple calculation based on perimeter components, thus facilitating efficient application in various geometrical problem-solving contexts. The provided Python example shows how to implement Heron's formula using basic arithmetic operations and demonstrates its practical application in computational geometry .

The order of operations is essential in computing geometric areas because it ensures that calculations follow the correct mathematical principles, preventing errors like incorrect squaring or multiplication. Python facilitates these computations by adhering to standard mathematical precedents, such as PEMDAS (Parentheses, Exponents, Multiplication and Division, Addition and Subtraction), thus automating the resolution of complex expressions. This allows users to write expressions naturally, confident that Python will compute them correctly, as seen in the Heron's formula application for area calculation .

The Python examples demonstrate string manipulation and repetition through user interactions that involve concatenating strings and repeating user input a specified number of times. For instance, the program asks for a user's name and a count, then repeats the name concatenated by itself. This exercise showcases Python's ability to handle and manipulate text efficiently, providing a simple introduction to string operations useful in user-based input scenarios, such as generating repeated patterns or constructing dynamic strings for outputs .

You might also like