In Java, If I want to print an incremented int variable, I can do it as:
int age = scn.nextInt(); System.out.println("You are " + age + " years old going on " + (age+1)); Output:
21 You are 21 years old going on 22 Is it possible to do the same in Python?
I tried the following, and none of them work.
age = input("How old are you?") print("You are " + age + " years old going on " + str(age+1)) print("You are " + age + " years old going on {}".format(age+1)) print("You are " , age , " years old going on " , str(age+1)) print("You are %d years old going on %d" %(age, age+1)) print("You are " + str(age) + " years old going on " + str(age+1)) I have already tried the solutions provided in these links:
Print Combining Strings and Numbers
Concatenating string and integer in python
age = int(input...ageis a string, not an integer. To solve the problem correctly, it is necessary to read an integer, use integers to do the math, and then convert back to string for concatenation (or format back into the string). This question needs more focus, and should be deleted; there are really two problems in one, and it results from a failure to debug or produce a minimal reproducible example.