vendredi 26 août 2016

Two Conditions but invalid syntax

So, I'm still a beginner in python. Right now, I want to create a small script that asked the user for their age.

Instead of asking for their age, I thought that I could, as a learning experience, have the script calculate their age based on their birth year. I also thought I could have the script check if the user's input was an integer and additionally check if the user's input had 4 digits.

Using an if-else statement, once the user's input passed these two conditionals it will print the user's age, else print an error.

My problem is I'm getting an invalid syntax error. The terminal is pointing at the "4" digit with the error.

import datetime

now = datetime.datetime.now()

print('Hello World')
print('What is your name?')
myName = input()
print('It is good to meet you ' + myName + '!')
print('The length of your name is: ' + str(len(myName)) + ' characters')
myAge = input('What year were you born: ')
if type(myAge) == int and len(str(myAge)) = 4
    print('You will be ' + str(now.year - int(myAge)) + ' this year!')
else
    print('That is not a number')

Aucun commentaire:

Enregistrer un commentaire