DO NOT DEAL WITH THIS MEMBER
Hey guys,
I am currently learning Python and I am a complete newbie so please do excuse me if this is the most simple mistake ever to you.
Would someone please tell me what is wrong with my code and why I get a syntax error when I try to run it ?
The code can be found below:
print("Hello, what is your name?")
myname = input("Enter your name")
if myname == "Oli"
print("Access granted.")
elif myname == "Adam"
print("You are on the wrong computer.")
else print("Access denied.")
Thank you guys, I know this may be incredibly easy for some of you but I am currently learning so please try refrain from laughing at me lol.
Thanks :)
-Oli
You're probably on 2.7.
Upgrade your python to 3.4
DO NOT DEAL WITH THIS MEMBER
(Jul 23, 2017 04:28 PM)Charger Wrote: You're probably on 2.7.
Upgrade your python to 3.4
I am using the latest version of Python
Jul 23, 2017 04:30 PM
(This post was last modified: Jul 23, 2017 04:31 PM by Retribute.)
You need a colon after the conditionals.
PHP Code
<?php print("Hello, what is your name?") myname = input("Enter your name")
if myname == "Oli": print("Access granted.")
elif myname == "Adam": print("You are on the wrong computer.")
else: print("Access denied.")
Code print("Hello, what is your name?")
myname = input("Enter your name")
if myname == "Oli":
print("Access granted.")
elif myname == "Adam":
print("You are on the wrong computer.")
else:
print("Access denied.")
Jul 23, 2017 04:33 PM
(This post was last modified: Jul 23, 2017 04:33 PM by ๖ۣۜSynapse.)
Code print("Hello, what is your name?")
myname = input("Enter your name")
if myname == "Oli":
print("Access granted.")
elif myname == "Adam":
print("You are on the wrong computer.")
else:
print("Access denied.")
Fixed it up for you. You were missing the colons after the if statements and the indents before the results.
EDIT: I was beat to it, rip.
DO NOT DEAL WITH THIS MEMBER
(Jul 23, 2017 04:30 PM)Retribute Wrote: You need a colon after the conditionals.
PHP Code
<?php print("Hello, what is your name?") myname = input("Enter your name")
if myname == "Oli": print("Access granted.")
elif myname == "Adam": print("You are on the wrong computer.")
else: print("Access denied.")
Thank you so much, got it working now :) I know it was a newbie mistake but thanks anyway haha
Jul 24, 2017 03:50 AM
(This post was last modified: Jul 24, 2017 03:51 AM by koolkid.)
OP even thou your just learning the language try to practice to keep the code clean and try to always add comments to your work so if you look back at it in say 10 or 20 year you know what you were doing .
PHP Code
<?php myname = input("Hello, what is your name? : ") #myname is a variable which holds a user's inputted name.
if myname == "Oli" :#conditional statement which checks to see if the user inputted Oli, if it is met then print the message below print("Access granted.") elif myname == "Adam":#conditional statement which checks to see if the user inputted Adam, if it is met then print the message below print("You are on the wrong computer.")
else: #if the conditions above are not met then print Access denied print("Access denied.")
Knowledge is Power - Be Powerful!!!!!
LIFE IS A CHALLENGE SO ACCEPT IT!
(Jul 24, 2017 03:50 AM)koolkid Wrote: OP even thou your just learning the language try to practice to keep the code clean and try to always add comments to your work so if you look back at it in say 10 or 20 year you know what you were doing .
PHP Code
<?php myname = input("Hello, what is your name? : ") #myname is a variable which holds a user's inputted name.
if myname == "Oli" :#conditional statement which checks to see if the user inputted Oli, if it is met then print the message below print("Access granted.") elif myname == "Adam":#conditional statement which checks to see if the user inputted Adam, if it is met then print the message below print("You are on the wrong computer.")
else: #if the conditions above are not met then print Access denied print("Access denied.")
I wouldn't recommend commenting your code like this. For simple scripts like what you're creating, you should be able to read it fluently without any comments. If you're just starting off, sure, but when you're larger scripts, commenting should only be done where you'll think you need it.
Don't narrate your script, it's not a book.
Skype messages are NOT valid evidence, and here's why.
DO NOT DEAL WITH THIS MEMBER
You was missing a colon after your final conditonal.
Perhaps consider sanitizing input and comparing as case-insensitive by applying the .lower() or .upper() method on strings in your conditionals.
DO NOT DEAL WITH THIS MEMBER
Thank you to everyone who responded, I have taken all of your replies into consideration :)
|