Hello,

I am new to this site, and new to programming. I am currently pursuing an associates in associates in programming and am taking an intro class to python, but i am having a serious issue with raw_input.

For some reason i am having a hard time understand raw_input and its intended use. I have no idea why im having such difficulties. I searched this site and could not find what i was looking for. I looked it up in the pythin glossary and that wasnt very helpful.

if someone could help me out. For example i am currently in the process of programming a stock trader program and im curious how i would use raw_input in relation to ticketers like pep for pepsi or f for ford in relation to an equation

i don't know if i explained that to well but i hope i can get some help.

raw_input is used for user input on the command line, or in IDLE for example:

word=raw_input('Enter a word: ')
print word

it is important to note that raw_input does not work in python 3.x it was combined with input() after python 2.

If you're not sure which one you are using, if you try to use raw_input and get an error regarding the raw_input, you are probably using python 3. In which case the code above would look like this:

word=input('Enter a word: ')
print(word)

Also, post code to show effort in. Effort in effort out, more specifically as Pytony would say http://www.daniweb.com/software-development/python/threads/359823

but what is its purpose in relation to variable equations?

to reference my stock trader example if a user wanted to buy 20 pepsi stocks could i do

stock=raw_input(20pep)
total=stock*cost

i know this wouldnt work but that is what im trying to understand is raw_input vs input in terms of equations.

It seems to me that raw_input was more for strings whereas input was for numeralsokay, so for python 2.7, which apparently is what you're using you could do "assuming the user knows the ticker code:

stockname=raw_input('What stock would you like to purchase?: ')
'''we are going to pretend you have a dictionary of prices for the ticker names'''
prices={'pep':62.07}
if stockname in prices.keys():
   stock_unit_price=prices[stockname]
amount=input('How many shares would you like?: ')
total_price=float(amount)*float(stock_unit_price)
'''I used float() because we are talking about stocks which often can be like 58.29, which is a floating point number'''
print('Your total is $',total_price)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.