# [SOLVED] Python: Functions & Loops. Error: ValueError: invalid literal for int() with base 10:

## Issue

I am learning Python functions and loops; however, I am running in to an error when trying to calculate two variables assigned to an integer within a loop, I post my code below as well as a draw.io diagram so better explain what I am trying to accomplish:

in the included image the green represents a working loop, or function and the red represent a broken loop or function, the white represents not yet coded

in the included code, the loops work on input option m and l, however the loop does not work on option q. the q option will also not work with additions with the w,e and r options.

P.S I have coded nothing in the w, e, r or y options yet (as you can see) however I have assigned integers to the q,w,e and r variables.

``````q = 1
w = 2
e = 3
r = 4

def exitprogram():
print ("exiting...")

def q_function():
Q_loop = True
while Q_loop:
print("Q function selected, select addition - press k to go back or x to exit")
print("")

#exit program
exitprogram()
break

q_w = q+w
print(q_w)

start()

#invalid input
else:
print("invalid input - try again")
continue

def w_function():
print("W function operational")

def e_function():
print("E function operational")

def r_function():
print("R function operational")

def t_function():
T_loop = True
while T_loop:
T_selection = input("T function operational - press k to go back or x to exit ")
if T_selection == "k":
more()
elif T_selection == "x":
exitprogram()
break

else:
print("invalid input - try again")
continue

def y_function():
print("Y function operational")

def more():
moreloop = True
while moreloop:
l = input ("select t or y - to go back select k to exit select x ")
if l =="t":
t_function()
break
if l =="y":
y_function()
break
if l =="x":
exitprogram()
break
elif l =="k":
start()
else:
print("invalid input - try again")
continue

def start():
loop1 = True
while loop1:
a = input("select q, w, e or y - for more options select m or to exit select x ")
if a == "x":
exitprogram()
break
elif a == "q":
q_function()
break
elif a == "w":
w_function()
break
elif a == "e":
e_function()
break
elif a == "r":
r_function()
break

elif a =="m":
more()
break

else:
print("invalid input - try again")
continue
start()
``````

Error traceback included below

`````` Traceback (most recent call last):
File "x:/xxx/xxx/xxxx/xxxx.xx", line 115, in <module>
start()
File "x:/xxx/xxx/xxxx/xxxx.xx", line 95, in start
q_function()
File "x:/xxx/xxx/xxxx/xxxx.xx"", line 16, in q_function
ValueError: invalid literal for int() with base 10: 'w'
``````

## Solution

You have `Q_addition = int(input("Add Q with "))` so are attempting to cast the input (x, k, e, etc) to an int. This throws the error. Also your logic checks for strings not int

``````#exit program
Q_loop = False #set the loop variable to false to exit the loop and return to main function
#changed to elif as Q_addition can only be one option
...
#if you'd like addition with the other variables need to add them
q_e = q+e
print(q_e)
remove the `int()` cast so `Q_addition = input("Add Q with ")`