Thread: Python 3.0
View Single Post
Old 06-07-2009, 09:49 AM   #15 (permalink)
Candiarie
Registered User
 
Candiarie's Avatar
 
Join Date: Jan 2003
Posts: 978
+0 Internets
Quote:
Originally Posted by MrGraham View Post
I'm running through the Python intro for fun as well. My programming experience is limited to HTML, Coldfusion, PHP, and SQL, so this question might be stupid for people who have worked with C.

Question - the following lines are from one of the first pages of the tutorial.
Code:
>>> word = 'Help' + 'A'
>>> word
'HelpA'
>>> '<' + word*5 + '>'
''
Why does the last line have to have the " + "'s around word*5 to work?
Code:
>>> word*5
'HelpAHelpAHelpAHelpAHelpA'
>>> ''
''
>>> '<'word*5'>'
SyntaxError: invalid syntax (, line 1)
... even with the code tag it's still omitting some.

An Informal Introduction to Python — Python v3.1a0 documentation

That's the page, it's like halfway down, section on concatenates.

Don't understand why '<' + word*5 + '>' works but '<'word*5'>' does not.
Assuming I'm not a complete idiot:
The +s concat those strings. Without that it has no idea what you're trying to do. It'd be like typing
5 3*5 5
into a calculator. It doesn't know that you're trying to add them together.


For the user input problem, you can print out the usercmd to see what it receives from the input(). That or run it through a debugger to find out why it's not working. Maybe remove the ORs to see if it works without. It's been a long time since I used Python 2 even so I'm not 100% on the syntax at all.
__________________
Candiarie is offline   Reply With Quote

 
Uberguilds Network