I wrote a program to output some simple numbers and strings to the user after reading them from the user.
In order to print and use math operators, I had to convert the datatypes multiple times in order to print it the way I want it.
Here's my code:
print("What is your name?")
name = input()
print("What is your age?")
age = input()
print(type(age))
print("Check for type")
print("We will now add your " + age + " years to 50.")
age = int(age)
print(type(age))
print("Check for type")
finalAge = 50 + age
finalAge = str(finalAge)
age = str(age)
print("In 50 years " + name + " will be " + finalAge + " years old.")
Here's the output:
What is your name?
Gavin
What is your age?
23
<class 'str'>
Check for beginning
We will now add your 23 years to 50.
<class 'int'>
Check for end
In 50 years Gavin will be 73 years old.
The bottom line is that I am looking for a better way to not have to convert types multiple times before the program finishes. Open to any suggestions!