Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first code
#1
My first code I've ever made in python doesn't work and I don't know why. Please can you help me solve the issue.
Code:


age = 10;
if age < 9:
    print("Hey! ")
    print("Welcome to play with us")
else
    print("You're too old for this gang!")
Error code: 


Error:
>>> %Run test.py   File "C:\Users\vikto\Desktop\test.py", line 5     else        ^ SyntaxError: invalid syntax >>>
Reply
#2
I'm not sure where you saw "%Run" and thought it would work.

It looks like you were in a command prompt and typed "python" to get the >>>. Instead, go back to that and type "python your_script_name.py". I recommend not using test.py as a name, for reasons that I don't want to overwhelm you with as a brand-new programmer.
Reply
#3
(Mar-02-2017, 05:10 PM)micseydel Wrote: I'm not sure where you saw "%Run" and thought it would work.

It looks like you were in a command prompt and typed "python" to get the >>>. Instead, go back to that and type "python your_script_name.py". I recommend not using test.py as a name, for reasons that I don't want to overwhelm you with as a brand-new programmer.

I used Thonny to write and run the code. But do you have to solution to my problem?
Reply
#4
Apologies, I misread the original problem.

You need a colon after "else"
Reply
#5
Thanks!
Reply
#6
In Python there is no ';' after a statement. Only if you do it on on line:

a = 2; b = 3; c = 'four'
Or may be I am wrong. Just tried it. Hm! :D
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
try this code :) 

age = 10 ## no need ; 
if age < 9:
    print("Hey! ")
    print("Welcome to play with us")
else: ## need :
    print("You're too old for this gang!")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020