+ 1

What's wrong?

I'va started a few weeks ago, and this is my first code, but everything is wrong and i don't know why, can you help me? a = [1,"Actualizar Stock"] b = [2,"Realizar Pedido"] c = [3,"Consultar Stock"] k = input("Ingrese opcion: ") if k == line(a[0]): print("nuevo menu") else: if k == line(b[0]): print("New menu") else: if k == line(c[0]): print("al fin")

14th Dec 2017, 7:31 PM
Alfredo Moreno
6 Answers
+ 1
int is short for integer or whole number (1, -3, 72). What version of Python are you using? I've tested the code in sololearn's code playground and its working... I really dont know what could make those errors. Google search each error. Have fun :)
14th Dec 2017, 10:27 PM
Ice
Ice - avatar
0
Can you tell me what were you trying to do? I dont know to program in python, but I may be able to help you...
14th Dec 2017, 7:52 PM
Ice
Ice - avatar
0
i was trying to generate a menu where the user put a number (1, 2 or 3) and it will redirect them to other menu
14th Dec 2017, 8:14 PM
Alfredo Moreno
0
Oh, i got it. If you use just input, then the numbers wont be recognized (they are considered as a letters/string - so if you're using just input you will need to write "1" "2" etc.). You need to use int(input()). Also you have elses where you dont need them. So your code should look like this: a = [1,"Actualizar Stock"] b = [2,"Realizar Pedido"] c = [3,"Consultar Stock"] k = int(input("Ingrese opcion: ")) if k == (a[0]): print("nuevo menu") if k == (b[0]): print("New menu") if k == (c[0]): print("al fin") or I would do it on this way: print ("1.Actualizar Stock") print ("2.Realizar Pedido") print ("3.Consultar Stock") k = int(input("Ingrese opcion: ")) if k==1: print ("nuevo menu") if k==2: print ("New menu") if k==3: print ("al fin")
14th Dec 2017, 8:48 PM
Ice
Ice - avatar
0
ok, i've run it, but it return this error: Ingrese opcion: Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: ' print("nuevo menu")' >>> ... ... File "<stdin>", line 3 if k == (b[0]): ^ SyntaxError: invalid syntax >>> File "<stdin>", line 1 print("New menu") ^ IndentationError: unexpected indent >>> ... ... But it appears that the general problem was the "else" use that i have, so i've tried your way but without int, bue got this after succefully putting a chouce (number) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'i2' is not defined What does int do?? thank you for your time :)
14th Dec 2017, 10:19 PM
Alfredo Moreno
0
the latest version, ok thanks for answering me,i'll keep testing
14th Dec 2017, 11:17 PM
Alfredo Moreno