python can't add int on string 1

python can’t add int on string

giorno = input()
print(9 + int(giorno))

Here is what the above code is Doing:
1. It asks the user to input a day of the week.
2. It stores the user’s input in a variable called giorno.
3. It prints the number 9 plus the number that the user input.

The last line is the most interesting.

The variable giorno is a string, because the user input is always a string.

But the number 9 is an integer.

So, we need to convert the string giorno to an integer before we can add it to 9.

We do that with the int() function.

The int() function takes a string and converts it to an integer.

So, int(giorno) converts the string giorno to an integer.

Then, we add that integer to 9.

The result is that we print the number 9 plus the number that the user input.

Similar Posts