1
myAge = input()
print('you  will be ' + str(int(myage) + 1) + 1 'in a year')

This code always returns:

invalid line base 10.

How can I correct this error?

4 Answers 4

1

Whenever you are parsing a string as integer by using int(), make sure that the string contains a valid number and no invalid characters. For example, if you give 23a as input, the invalid a character will cause the error that it is not a valid literal for int base 10.

The code works fine for me, apart from the small typo you have in the code just before the string 'in a year' (there should not be 1). And also, myage and myAge are different.

>>> myAge = input()
>>> print('you  will be ' + str(int(myAge) + 1) + ' in a year')

This works fine.

Sign up to request clarification or add additional context in comments.

Comments

0

Seems like you need to read an input from user and add a number and then print it:

myAge = input()
print("you will be " + str(int(myAge) + 1) + " in a year")

or

myAge = input()
myAge = int(myAge) + 1
print("you will be " + str(myAge) + " in a year"

(It's python3 syntax)

Comments

0
myAge=input("Enter your Age: ") #asks for input

myAge = int(myAge)+1 #converts myAge into an integer and adds one

print("You will be "+str(myAge)+" in a Year") #converts back myAge into a str and prints it

OUTPUT

Enter your Age: 79
You will be 80 in a Year

2 Comments

Thanks so much. I found when running the program I did not input number in input function. Thanks you all
You are welcome. Wish you a good programming session
0

You have a stary '1' after the cast to str. Try the following:

myAge = input()
print('you  will be ' + str(int(myAge) + 1) + ' in a year')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.