Answer to Question #196085 in Python for reeeg

Question #196085

help please check! i can run the code, but i can't input and output words and numbers.

dict1 {'a':2,'b':2,'c':2,'d':3,'e':3,'f':3,'g':4,'h':4,'i':4,'j':5,'k':5,'l':5,'m':6,'n':6,'o':6,'p':7,'q':7,'r':7,'s':7,'t':8,'

u': 8,'v':8,'w':9,'x':9,'y':9,'z':9}

def convert(word):

x = 0 for i in range(0,len(word)):

ch = word[i] x = x * 10 + dict1[ch]

return x n = int(input())

words =[] T9=[]

for i in range(0,n): words.append(input())

T9.append(convert(words[i])) case1=[]

t = int(input()) for i in range(0,t):

cases1.append(input()) for i in range(0,t): x = cases1[i].split(' ')

 y = 1 print("Message #",(i + 1), ",:", end = " ")

 for j in x:  y = y * T9.count(int(j))

if y == 0: print("Not valid. Please enter a valid text")

elif y!=1: print("There are ",y," possible messages")

else: for j in x:

print(words[T9.index(int(j))],end = " ")


1
Expert's answer
2021-05-20T10:58:11-0400
#here you forgot to put an equal sign
dict1 = {'a':2,'b':2,'c':2,'d':3,'e':3,'f':3,'g':4,'h':4,'i':4,'j':5,'k':5,'l':5,'m':6,'n':6,'o':6,'p':7,'q':7,'r':7,'s':7,'t':8,'u': 8,'v':8,'w':9,'x':9,'y':9,'z':9}


def convert(word):


	x = 0
	for i in range(0,len(word)):
		ch = word[i]
		x = x * 10 + dict1[ch]
	return x


n = int(input())
words =[]
T9=[]


for i in range(0,n):
	words.append(input())
	T9.append(convert(words[i]))
#here you declared the variable "case1" but later in the code you used the variable name "cases1"
case1 = []
t = int(input()) 


for i in range(0,t):
	case1.append(input())


for i in range(0,t):
	x = case1[i].split(' ')
	y = 1
	print("Message #",(i + 1), ",:", end = " ")


	for j in x:
		y = y * T9.count(int(j))


		if y == 0:
			print("Not valid. Please enter a valid text")


		elif y != 1:
			print("There are ",y," possible messages")


		else:
			for j in x: 
				print(words[T9.index(int(j))],end = " ")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS