Building a Basic Numpad with Python

2 minute read
0




This code is a simple Python script that defines and prints a 2D list that represents a numeric keypad.
The 2D list keys contains 3 lists, each representing a row of keys on the keypad.
The script uses nested for loops to iterate over the outer list (keys) and inner lists (key).
For each inner list, it loops over its elements (i) and prints each element, followed by a space, using the end parameter in the print function.
After printing all elements of an inner list, it moves to the next line with a separate call to print with no arguments.
The output of the code will show the numbers on the keypad in a clear and organized format, making it easy to understand and follow.
This code can be useful as a starting point for developing a program that uses a keypad, 
such as a calculator or a security system.



/*The code uses the following concepts:*/

1)Lists: keys is a 2D list that represents the numeric keypad. 
  It contains 3 lists, each representing a row of keys on the keypad.
2)For Loops: The code uses two for loops, one inside the other, to iterate over the elements in the keys list. 
  The outer loop iterates over each inner list (key), and the inner loop iterates over each element in the inner list (i).
3)Print Function: The code uses the print function to output the elements in the list. 
  The end parameter is used to specify what should be printed at the end of each print statement. 
  In this case, it is set to a space (" ") so that the elements are separated by spaces.
4)End of Line: The code uses a separate print statement with no arguments to move to a new line after printing all elements of an inner list.
  This ensures that each row of the keypad is printed on a separate line.



CODE:

keys=[[1,2,3],[4,5,6],["*",0,"#"]]
for key in keys:
  for i in key:
    print(i,end=" ")
  print()




Here is a simple python program of  Numpad.

Just copy the code and paste it in your preferred Code Editor.

if you have any Doubt Feel Free to comment down,Our team will Respond as soon as Possible.

Thanks for Reading,

Regards,

Team Dekoders.



Tags

Post a Comment

0Comments
Post a Comment (0)