6
6
print ('3 \t \t ' + str (3 * 3 ))
7
7
print ('4 \t \t ' + str (4 * 4 ))
8
8
9
+ # output:
10
+ # Numbers Squares
11
+ # 1 1
12
+ # 2 4
13
+ # 3 9
14
+ # 4 16
9
15
10
16
# method 2:
11
17
def number_squares (start_num ,end_num ):
@@ -16,13 +22,28 @@ def number_squares(start_num,end_num):
16
22
print (f"{ n } \t \t { n * n } " )
17
23
18
24
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 (' ' ))
20
26
print ('Numbers\t \t Squares' )
21
27
number_squares (start_num ,end_num )
22
28
except ValueError :
23
29
print ("Invalid input! Please enter two integers separated by a space." )
24
30
25
31
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
+
26
47
# Assignment 1:
27
48
# In Python to find the range of numbers that are both squares and cubes within a specified limit
28
49
def number_square_cubes (start_num ,end_num ):
@@ -33,13 +54,28 @@ def number_square_cubes(start_num,end_num):
33
54
print (f"{ n } \t \t { n * n } \t \t { n * n * n } " )
34
55
35
56
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 (' ' ))
37
58
print ('Numbers\t \t Squares\t \t Cubes' )
38
59
number_square_cubes (start_num ,end_num )
39
60
except ValueError :
40
61
print ("Invalid input! Please enter two integers separated by a space." )
41
62
42
63
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
+
43
79
# Time Complexity
44
80
45
81
# The main time complexity comes from the loop, which iterates over the numbers in the range [start_num, end_num].
0 commit comments