Reputation: 3
I'm new to programming and learning python using VSCode as my IDE.
# 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.
Upvotes: 0
Views: 197
Reputation: 166
In the directory with your age.py
file, you also have a math.py
file. The datetime
module (which you use by typing import datetime
) is looking for the Python math module, math.py
. But it's finding your math.py
file first.
The issue is in that file, not in your age.py
file. There's apparently a line that starts with Python 3.7.0...
that isn't valid Python syntax. You should probably rename math.py
to something like my_math.py
, which should resolve the issue.
Upvotes: 3