I get a value error when I change strings to integers [duplicate]

You might want to change the hints in between the quotes. The input needs to be entered with the keyboard, and the phrase in between the quotes is the hint that you will see while entering the input.

This way, you will be prompted for entering an input for the variable v1 first and then for the variable v2. You should make sure you do not enter any space or string, just the number you want to sum. Alternatively, you can also implement a system that checks that the user input is a number or, otherwise, asks the user to introduce the number again.

The option 1 would be:


v1 = input ('Please Introduce the first number')

v1 = int(v1)

v2 = input('Please introduce the second number')

v2 = int(v2)

total = int(v1) + int(v2)

print ("the sum of", v1, "and", v2, "is?", total )

Option 2 (checking that the user entered a number):


correctNumbers = False

while (not correctNumbers):

    try:
        v1 = input ('Please introduce the first number')
        v2 = input ('Please introduce the second number')
        v1 = int(v1)
        v2 = int(v2)
        correctNumbers=True
    except:
        print ("At least one of the two numbers contained a wrong character, please try again.")

total = int(v1) + int(v2)

print ("the sum of", v1, "and", v2, "is?", total )

I hoped it helped to solve your doubt :)