I'm new to programming and learning python using VSCode as my IDE.
- For an exercise, I created a python script in VSCode that tells the user in what year they will turn 100 years old. Below is the code:
# gets user age and prints the year user will be 100 years old
import datetime
cDate = datetime.datetime.now()
cYear = int(cDate.year)
uName = input("Hi, what is your name?: ")
print ("Hello " + uName)
print ("I will tell you what year you will turn 100 years!")
uAge = int(input("How old are you?: "))
year100 = cYear - uAge + 100
print ("You will be 100 years old in the year " + str(year100) + "!.")
The code is supposed to ask user for name, age then calculate and print out the year the user will be 100 years of age.
When I ran it on VSCode, I got the error message below:
Traceback (most recent call last):
File "/Users/me/Documents/Education/phyton/exercises/age in 100 years.py", line 3, in <module>
import datetime
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/datetime.py", line 8, in <module>
import math as _math
File "/Users/me/Documents/Education/phyton/exercises/math.py", line 1
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
^
SyntaxError: invalid syntax
I believe the problem may lie in the VSCode python configuration having tested the same code in IDLE where it ran perfectly.
So far I have installed python 3.8 (previously had 3.7 installed) with no effect.
My system details include: - macOS Catalina - Python 2.7 and 3.8 installed
Please do not hesitate to ask if you have any other questions.
/Users/me/Documents/Education/phyton/exercises/math.py