This forum is in archive mode. You will not be able to post new content.

Author Topic: Python run-time error.  (Read 1216 times)

0 Members and 1 Guest are viewing this topic.

Offline IntelAnon

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 1
    • View Profile
Python run-time error.
« on: August 04, 2013, 05:53:59 AM »
This is my first computer language and I am going through my first tutorial.

print("Hello")
username = Joe
print(username)

Why won't Python assign "Joe" as the output ( I guess that's how i'll put it ) to the variable "username"?

Correct ANYTHING (use of words and my actual problem)

Thanks.
« Last Edit: August 04, 2013, 05:54:26 AM by IntelAnon »

Offline parad0x

  • VIP
  • Royal Highness
  • *
  • Posts: 638
  • Cookies: 118
    • View Profile
Re: Python run-time error.
« Reply #1 on: August 04, 2013, 06:19:31 AM »
The problem is because you have typed
Code: [Select]
username = JoeThis makes python think that Joe is a variable, not a string constant. If you want to think python it as a string, do
Code: [Select]
username = "Joe"
You can use single quotes instead of double quotes. That's a matter of choice. Look here
Code: (Python) [Select]
username = "Joe" and
Code: (Python) [Select]
username = 'Joe'both are same things. ;)

Cheers!
parad0x
« Last Edit: August 04, 2013, 06:25:33 AM by parad0x »

Offline IntelAnon

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 1
    • View Profile
Re: Python run-time error.
« Reply #2 on: August 04, 2013, 06:25:08 AM »
Okay, thank you very much. I guess I was confused from the progress of the tutorial. It starts with explaining in mathematics and logic, where the tutorial would not have you put quotes around say 1.
For example,
>>> username="joe"
>>> un=1
>>> print(username)
joe
>>> print(un)
1
>>>

Any further explanations, please?

Offline parad0x

  • VIP
  • Royal Highness
  • *
  • Posts: 638
  • Cookies: 118
    • View Profile
Re: Python run-time error.
« Reply #3 on: August 04, 2013, 06:27:52 AM »
Yes, all the numbers are constants, you cannot change them.
Therefore
Code: [Select]
un = 1 is right but
Code: [Select]
username = Joe is wrong until Joe is a variable or constant.

Try doing
Code: [Select]
0 = 1 and you'll see an error saying "cannot assign value to literal".

Constants and variables are written without the quotes whereas strings and characters are written using quotes.
« Last Edit: August 04, 2013, 06:35:10 AM by parad0x »

Offline IntelAnon

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 1
    • View Profile
Re: Python run-time error.
« Reply #4 on: August 04, 2013, 06:45:59 AM »
Okay thank you parad0x, I'll be sure to go over what you just stated tomorrow. It is almost 1am. This is more then likely causing my fog. On a "brighter" note, I am thoroughly enjoying learning this language! I don't know exactly what I plan on doing with it, or what I can do with it. Even though I know a little about computers and have done challenges, I still consider myself very new.
 

Offline parad0x

  • VIP
  • Royal Highness
  • *
  • Posts: 638
  • Cookies: 118
    • View Profile
Re: Python run-time error.
« Reply #5 on: August 04, 2013, 06:57:22 AM »
Okay thank you parad0x, I'll be sure to go over what you just stated tomorrow. It is almost 1am. This is more then likely causing my fog. On a "brighter" note, I am thoroughly enjoying learning this language! I don't know exactly what I plan on doing with it, or what I can do with it. Even though I know a little about computers and have done challenges, I still consider myself very new.
Python is an excellent scripting language to automate various tasks. It has powerful libraries, easy to use syntax. So basically, you can use python from automating your tasks to make hacking tools to automate hacking for you.


Python is worth learning.Have fun with python.
« Last Edit: August 04, 2013, 06:58:20 AM by parad0x »

Offline RedBullAddicted

  • Moderator
  • Sir
  • *
  • Posts: 519
  • Cookies: 189
    • View Profile
Re: Python run-time error.
« Reply #6 on: August 04, 2013, 10:34:03 AM »
Nice parad0x :) Just a little addition to what you already explained

Code: [Select]
>>> number = 1
>>> type(number)
<type 'int'>
>>> number = "1"
>>> type(number)
<type 'str'>
>>> username = "joe"
>>> type(username)
<type 'str'>
>>> print(username)
joe
>>> joe = "evilzone"
>>> username = joe
>>> print(username)
evilzone

Hope this helps

Cheers,
RBA
Deep into that darkness peering, long I stood there, wondering, fearing, doubting, dreaming dreams no mortal ever dared to dream before. - Edgar Allan Poe

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.