File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ # method 1
2
+ print ('Numbers\t \t Squares' )
3
+ print ('1 \t \t ' + str (1 * 1 ))
4
+ print ('2 \t \t ' + str (2 * 2 ))
5
+ print ('3 \t \t ' + str (3 * 3 ))
6
+ print ('4 \t \t ' + str (4 * 4 ))
7
+
8
+
9
+ # method 2
10
+ def number_squares (n ):
11
+ print (str (n )+ ' \t \t ' + str (n * n ))
12
+
13
+ start_num ,end_num = input ('enter the starting and ending number:' ).split (' ' )
14
+ if start_num <= end_num :
15
+ for n in range (int (start_num ),int (end_num )+ 1 ):
16
+ number_squares (n )
17
+ else :
18
+ print ('enter the proper range' )
19
+
20
+
21
+ # method 3 : optimized
22
+
23
+ def number_squares (start_num ,end_num ):
24
+ if start_num > end_num :
25
+ print ('Invalid Range: Starting number must be less than or equal to the ending number.' )
26
+ return
27
+ for n in range (start_num ,end_num + 1 ):
28
+ print (f"{ n } \t \t { n * n } " )
29
+
30
+ try :
31
+ start_num ,end_num = map (int ,input ('Enter the starring and ending range with single space:' ).split (' ' ))
32
+ print ('Numbers\t \t Squares' )
33
+ number_squares (start_num ,end_num )
34
+ except ValueError :
35
+ print ("Invalid input! Please enter two integers separated by a space." )
You can’t perform that action at this time.
0 commit comments