Dec-02-2018, 08:51 PM
Hi,
This is a program I wrote this morning, to play around with nested loops,
and error handling routines.
It will convert any 7 digit phone number into all the 2000 plus letter
combinations that make up the letters on the modern phone dial.
This is a program I wrote this morning, to play around with nested loops,
and error handling routines.
It will convert any 7 digit phone number into all the 2000 plus letter
combinations that make up the letters on the modern phone dial.
import os import os class klass: "docstring" def_int-self: self.attribute="var" if len (self.attribute)<2: pass #python program code starts here! print("") tuple0=("","","") tuple1=("","","") tuple2=("a","b","c") tuple3=("d","e","f") tuple4=("g","h","i") tuple5=("j","k","l") tuple6=("m","n","o") tuple7=("p","q","r","s") tuple8=("t","u","v") tuple9=("w","x","y","z") print("");print("");print("This program will return all the letter conbinations") print( "that are available on the modern phone") print("You just type in a seven digit number and let the program display") print("all the letter conbinations that make up that number Enjoy");print("") flg=0 quit=0 while quit==0: list_numbers=[] list_tuple=[] cont=0 while cont==0: print("") print (" Enter (0) to exit out of the program");print ("") try: phone_number=input("Enter a 7 digit phone number (NO spaces)>> ") dummy=int(phone_number) if (phone_number)=="0": flg=1 break elif len(phone_number)< 7: print("") print ("Do not enter less than (7) digits") elif len(phone_number)>7: print("") print ("Do not enter more than (7) digits") else: cont=1 except: print("") print ("Enter numbers only no letters or special characters") for number in (phone_number): print (number) list_numbers.append(number) if flg==1: break print("") print (list_numbers) for number in (list_numbers): if number =="0": list_tuple.append(tuple0) if number=="1": list_tuple.append(tuple1) if number=="2": list_tuple.append(tuple2) if number=="3": list_tuple.append(tuple3) if number=="4": list_tuple.append(tuple4) if number=="5": list_tuple.append(tuple5) if number=="6": list_tuple.append(tuple6) if number=="7": list_tuple.append(tuple7) if number=="8": list_tuple.append(tuple8) if number=="9": list_tuple.append(tuple9) print("") print(list_tuple) print("") print("") a=(list_tuple[0]) print (a) b=(list_tuple[1]) print(b) c=(list_tuple[2]) print (c) d=(list_tuple[3]) print(d) e=(list_tuple[4]) print(e) f=(list_tuple[5]) print (f) g=(list_tuple[6]) print (g) print("") n=1 for A in (a): for B in (b): for C in (c): for D in (d): for E in (e): for F in (f): for G in (g): print ("(",(n),") ",(A)+(B)+(C)+(D)+(E)+(F)+(G)) print("") n=n+1