Skip to content

Commit c94c182

Browse files
committed
Assignment 2: Calculate the Area of the Rectangle
1 parent 74a0045 commit c94c182

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

300_Exercises/Simple/1.numbers_and_squares.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
print('3 \t\t '+str(3*3))
77
print('4 \t\t '+str(4*4))
88

9+
# output:
10+
# Numbers Squares
11+
# 1 1
12+
# 2 4
13+
# 3 9
14+
# 4 16
915

1016
# method 2:
1117
def number_squares(start_num,end_num):
@@ -16,13 +22,28 @@ def number_squares(start_num,end_num):
1622
print(f"{n}\t\t{n*n}")
1723

1824
try:
19-
start_num,end_num=map(int,input('Enter the starring and ending range with single space:').split(' '))
25+
start_num,end_num=map(int,input('Enter the starting and ending range with single space:').split(' '))
2026
print('Numbers\t\tSquares')
2127
number_squares(start_num,end_num)
2228
except ValueError:
2329
print("Invalid input! Please enter two integers separated by a space.")
2430

2531

32+
# output:
33+
# Enter the starting and ending range with single space:10 20
34+
# Numbers Squares
35+
# 10 100
36+
# 11 121
37+
# 12 144
38+
# 13 169
39+
# 14 196
40+
# 15 225
41+
# 16 256
42+
# 17 289
43+
# 18 324
44+
# 19 361
45+
# 20 400
46+
2647
# Assignment 1:
2748
# In Python to find the range of numbers that are both squares and cubes within a specified limit
2849
def number_square_cubes(start_num,end_num):
@@ -33,13 +54,28 @@ def number_square_cubes(start_num,end_num):
3354
print(f"{n}\t\t{n*n}\t\t{n*n*n}")
3455

3556
try:
36-
start_num,end_num=map(int,input('Enter the starring and ending range with single space:').split(' '))
57+
start_num,end_num=map(int,input('Enter the starting and ending range with single space:').split(' '))
3758
print('Numbers\t\tSquares\t\tCubes')
3859
number_square_cubes(start_num,end_num)
3960
except ValueError:
4061
print("Invalid input! Please enter two integers separated by a space.")
4162

4263

64+
# output:
65+
# Enter the starring and ending range with single space:5 15
66+
# Numbers Squares Cubes
67+
# 5 25 125
68+
# 6 36 216
69+
# 7 49 343
70+
# 8 64 512
71+
# 9 81 729
72+
# 10 100 1000
73+
# 11 121 1331
74+
# 12 144 1728
75+
# 13 169 2197
76+
# 14 196 2744
77+
# 15 225 3375
78+
4379
# Time Complexity
4480

4581
# The main time complexity comes from the loop, which iterates over the numbers in the range [start_num, end_num].

300_Exercises/Simple/2.area_of_circle.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,41 @@
33
def area_of_circle(n):
44
print(f'Area of the circle {n} is {3.14*n*n}')
55

6-
n = float(input('Enter the n Number: '))
6+
n = float(input('Enter the area of circle N value : '))
77
area_of_circle(n)
88

9+
# output:
10+
# Enter the area of circle N value : 10
11+
# Area of the circle 10.0 is 314.0
912

1013
# method 2:
1114
import math
1215

1316
def area_of_circe(n):
1417
print(f'Area of the circle {n} is {math.pi*n**2}')
1518

16-
n = float(input('Enter the n Number: '))
19+
n = float(input('Enter the area of circle N value : '))
1720
area_of_circe(n)
21+
22+
# output:
23+
# Enter the area of circle N value : 20
24+
# Area of the circle 20.0 is 1256.6370614359173
25+
26+
# Assignment 2:
27+
# Calculate the Area of the Rectangle
28+
def area_of_rectangle(l,b):
29+
print(f'Area of rectangle with length {l} and breadth {b} is {l * b}')
30+
31+
l,b = map(float, input('Enter the Length and Breadth of the rectangle with single space: ').split(' '))
32+
area_of_rectangle(l,b)
33+
34+
# output:
35+
# Enter the Length and Breadth of the rectangle with single space: 10 20
36+
# Area of rectangle with length 10.0 and breadth 20.0 is 200.0
37+
38+
# Time Complexity:
39+
# The input handling (map(float, input().split())) takes constant time to process two values, so it's O(1).
40+
# The function call and the multiplication inside it also take constant time, so that part is O(1).
41+
42+
# Thus, the overall time complexity of the code is O(1),
43+
# meaning the runtime does not depend on the size of the input and remains constant.

0 commit comments

Comments
 (0)