-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment_1_practical_4.py
46 lines (41 loc) · 1.42 KB
/
assignment_1_practical_4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""Assignment-1 Practical-4.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1sqcHcFVj8yKiEriJzMO7M7h1DK9yoJKz
"""
#Practical-4:
#Create Input.txt manually write 3 float numbers in it.
#The first number is a radius, second is the width and last is the height
#Read all number form file Input.txt and
#calculate the following
#1) Area of Circle
#2) Area of Rectangle
#3) Perimeter of Circle
#4) Perimeter of Rectangle
#Write all answers in file Output.txt
#Opening file Input.txt in "w" mode
file1 = open("Input.txt","w")
file1.write(str(12.6)+"\n")
file1.write(str(25.9)+"\n")
file1.write(str(15.33)+"\n")
file1.close()
#opening Input.txt and output.txt in "r" and "w" mode respectively
file1 = open("Input.txt","r")
file2 = open("Output.txt","w")
radius = float(file1.readline())
length = float(file1.readline())
breadth = float(file1.readline())
#Calculating area and perimeter of Circle and Rectangle
area_circle = 3.14*radius*radius
area_rectangle = length*breadth
peri_circle = 2*3.14*radius
peri_rectangle = 2*(length+breadth)
#Writing data into file
file2.write("Area of circle is:"+str(area_circle)+"\n")
file2.write("Area of rectangle is:"+str(area_rectangle)+"\n")
file2.write("Perimeter of circle is:"+str(peri_circle)+"\n")
file2.write("Perimeter of rectangle is:"+str(peri_rectangle)+"\n")
#closing the files
file1.close()
file2.close()