Problem with script in Python

0

People, I have a slight problem with a script I created in Python.

print("Agora eu vou dizer algo para você.")
idade = int(input("Me diga sua idade."))
if idade < 18
print("Me desculpe, você não pode dirigir.")
else
print("Que bom, você pode dirigir!")
wait = input("Aperte qualquer tecla para sair do CMD.")
exit

The problem is: when I run it, it simply opens and quickly closes alone, without me even being able to do anything in it.

I'm starting to learn Python and programming now, so it's likely that I've made some stupid mistake, like some syntax, but I can not figure out what it is.

Well, I just created the script to test some things with Python, and from what you may have noticed, it's something simple.

The user sets his or her age and the script says whether the person can legally or not. I just want to solve the script, in fact, more to know what my mistake was and not to do it in the future, because the script itself is totally useless. So what would be the problem in the script that causes it to close itself?

    
asked by anonymous 02.07.2018 / 07:17

1 answer

2

Basically missing the ":" at the end of the line of if and else

print("Agora eu vou dizer algo para você.")
idade = int(input("Me diga sua idade."))

if idade < 18:
   print("Me desculpe, você não pode dirigir.")
else:
   print("Que bom, você pode dirigir!")

wait = input("Aperte qualquer tecla para sair do CMD.")
exit

I also lacked the indentation (indentation) in the lines of print , but this may have been a problem when you posted the question, I imagine that in your original code there are indents (if not, add).

See the code working perfectly on IDEONE . (with mock input of 19 for the first input , and x for the second)

    
02.07.2018 / 08:00