Syntax Error in print

0

I am new using Python so I am taking a course. Our challenge was to make a small program that calculates in what year you will be 100 years old. In line 8, I am marked with an error in the syntax, how can I solve it? Here is my code:

import string
import random
import age

date = 2017+100
name = input("Enter your name: ")
print()
age = int(input("Enter your age: ")

print ("So, you will be 100 years old in " + age + -(int(date)))
time.sleep(20)
    
asked by Josué Magro 08.10.2017 в 04:11
source

2 answers

0
print ("So, you will be 100 years old in " + age + -(int(date)))

This line is wrong because you concatenate two int with a string and can not be in python. If you would like to link the text with age and date you need to convert those variables to string . It would be something like this:

print ("So, you will be 100 years old in " + str(age) + "-" + str(date))

Or you could also use format which is the best for formatting texts.

print ("So, you will be 100 years old in {} -{}".format(age, date))
    
answered by 08.10.2017 в 06:57
0

Many times it's good to keep in mind how you want your program to be, since python allows you to do something that for example in C, would take you 10 lines to only two. So, solving your doubt, the print () that you have there on line 7 is useless, like the imports you do, because I do not see that you use random. I would do so the program, based on what you have written.

def Age(): #Así se define una función, para llamarla solo ingresa Age()
    resp = 'a' #Bandera para que inicie el programa
    while resp != 'Y':
    name = input("Enter u name: \n")
    age  = int(input("Enter u age: \n"))
    aux  = (100-age) + 2017
    print("So, ",name, " u'll b 100 yrs old in ", aux)
    resp = input("Do u finished Y/N:\n")

Greetings and keep playing with python

    
answered by 09.10.2017 в 06:50