Help! (Problem not stated)

This is the place for queries that don't fit in any of the other categories.

Help! (Problem not stated)

Postby KRE8OR88 » Thu May 08, 2014 8:38 pm

Please can you tell me what is wrong with this code! Thanks
[img]code1.png[/img]

Code: Select all
print("Please Login")

username=input("Username:")
if username=="blox2000":
    print("Username Authenticated."
else:
    print("Unknown Username.")
    import time
    time.sleep(1)
    quit()

password=input("Password")
if password=="poopoo123":
    print("Password Authenticated.")
else:
    quit()
print("Welcome back to the Avalonia Control Panel, Tom.")
Last edited by micseydel on Fri May 09, 2014 3:38 am, edited 2 times in total.
Reason: Yoriz: First post lock,Added to title. micseydel: added code tags.
KRE8OR88
 
Posts: 1
Joined: Thu May 08, 2014 8:34 pm

Re: Help!

Postby mckryall » Thu May 08, 2014 9:51 pm

Hi! Welcome. Try to copy or take a picture of the error you get when you try to run your script. Also, when posting code, use code tags - the "code" button in the post editor.
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Help!

Postby mckryall » Thu May 08, 2014 9:53 pm

First of all, it doesn't look like you used any indentation, and you wrote "rint" instead of "print". You seem to be using Python 3. When you type "python" into the terminal/command prompt, what does it say?
EDIT:
This version of your script should be fixed if you have python 3:
Code: Select all
import time
#-----
username = input("Please log in.\nUsername:\n> ")

if username == "blox2000":
   print("Username Authenticated.")
else:
   print("Unknown Username.")
   time.sleep(1)
   quit()

password = input("Password")

if password == "poopoo123":
   print("Password Authenticated.")
   
else:
   quit()
print("Welcome back to the Avalonia Control Panel, Tom.")
#If you want to display their username, do this:
#print("Welcome back to the Avalonia Control Panel, %s." % username)

EDIT EDIT:
You're not using CodeAcademy, are you? :shock:
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Help!

Postby dan » Thu May 08, 2014 11:12 pm

You also missed a closing parenthesis on this line:

Code: Select all
print("Username Authenticated."


Also, this line won't work with python 3:

Code: Select all
print("Welcome back to the Avalonia Control Panel, %s." % username)


It'll give invalid syntax. Instead, use:

Code: Select all
print('Welcome back to the Avalonia Control Panel {}'.format(username))


EDIT: Surround any code that you post with code blocks. That way it will keep your indentation, and will be much easier for others to read.
Python 3.4
Arch Linux
My github account
dan
 
Posts: 20
Joined: Mon Apr 21, 2014 1:29 pm

Re: Help!

Postby mckryall » Thu May 08, 2014 11:38 pm

Thanks for the formatting clarification. Why'd they change that? I liked using %.
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Help!

Postby dan » Fri May 09, 2014 7:34 am

mckryall wrote:Thanks for the formatting clarification. Why'd they change that? I liked using %.

Not a clue mate, I haven't been programming long. I only know that because I've been lurking around this forum lol (which by the way, to any n00bs like myself, is an AMAZING way to learn - you'll pick up tricks that you won't see in any of the tutorials - just take lots of notes 8-) )
Python 3.4
Arch Linux
My github account
dan
 
Posts: 20
Joined: Mon Apr 21, 2014 1:29 pm

Re: Help! (Problem not stated)

Postby Mekire » Fri May 09, 2014 8:07 am

dan wrote:Also, this line won't work with python 3:

Code: Select all
print("Welcome back to the Avalonia Control Panel, %s." % username)


It'll give invalid syntax. Instead, use:

Code: Select all
print('Welcome back to the Avalonia Control Panel {}'.format(username))

This is incorrect. The original % style formatting still exists in python 3.
Guido has personally stated that it is not going to go anywhere in the past (I'm trying to find the source for this; will edit when I have found it).

The new format method is definitely preferable in the vast majority of cases; but that doesn't make the other method a syntax error.

Code: Select all
C:\Users\Owner\Desktop>python3
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> username = "FredDave"
>>> print("Welcome back to the Avalonia Control Panel, %s." % username)
Welcome back to the Avalonia Control Panel, FredDave.
>>>

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Help! (Problem not stated)

Postby dan » Fri May 09, 2014 9:15 am

Ahh, I see the mistake I made when trying that - I used a comma inbetween the string and the variable, kind of like how it's done in C:

Code: Select all
x = 'world'
print('hello %s', %x)


Cheers for clearing that up Mek :D
Python 3.4
Arch Linux
My github account
dan
 
Posts: 20
Joined: Mon Apr 21, 2014 1:29 pm

Re: Help!

Postby XndrK » Fri May 09, 2014 6:28 pm

dan wrote:
mckryall wrote:Thanks for the formatting clarification. Why'd they change that? I liked using %.

Not a clue mate, I haven't been programming long. I only know that because I've been lurking around this forum lol (which by the way, to any n00bs like myself, is an AMAZING way to learn - you'll pick up tricks that you won't see in any of the tutorials - just take lots of notes 8-) )


From what I've heard, they switched to the "I am a {}!".format("string") method because it's a lot easier to read.

I have also heard that the "I am a %s!" % ("string") format (the old format) is based on a method that does the same thing in C.

Meh.
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm

Re: Help! (Problem not stated)

Postby micseydel » Fri May 09, 2014 7:10 pm

I thought I remembered hearing that the old formatting would eventually be removed, so I looked into it a bit. It appears that in old documentation said it would be removed, but newer documentation does not, and other new documentation is more aggressive about suggesting it not be used, which is probably because they really want people to stop using it even though it will stick around.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1369
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Help! (Problem not stated)

Postby XndrK » Wed May 14, 2014 11:16 pm

Well, duh, they are keeping it; they don't want to go to Python 4 just yet.

Why would they have to change the version number, you might ask?

Two words: Semantic versioning.

In short, every time you make a backwards incompatible release, you have to add 1 to the first number; every time you insert a new feature to a release, you add 1 to the second number; and every time you do a bugfix release, you add 1 to the third number.

I hope you already knew that, but if you didn't, here goes.
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm


Return to General Coding Help

Who is online

Users browsing this forum: buran, Google [Bot] and 2 guests