Problem with Python script

Asked

Viewed 87 times

0

Guys, 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 just opens and quickly closes itself, without me even being able to do anything on it.

I’m starting to learn Python and programming now, so it’s likely I made some stupid mistake, like a syntax thing, but I can’t notice what it is.

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

The user puts their age and the script says whether the person can drive legally or not. I just want to solve the script, actually, 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?

1 answer

2

Basically missing the ":" at the end of the if and of 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

Also missing 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 indentations (if not, add).

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.