Home | Community | Message Board


This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: Unfolding Nature Unfolding Nature: Being in the Implicate Order   Myyco.com Golden Teacher Liquid Culture For Sale

Jump to first unread post Pages: 1
Python Programmers HELP?!
    #21300764 -

I'm trying to learn python using MIT opencourseware..
first assignment is to write a program which

1. Asks the user to enter his/her last name.
2. Asks the user to enter his/her first name.
3. Prints out the user’s first and last names in that order.

I can get 1 and 2 down but when it comes to printing the first and last name in order, I just cant seem to figure it out.

Where am I going wrong here?



print (raw_input('Last name?'))(raw_input('First name?'))
x=raw_input('First name?')
y=raw_input('Last name?'))
print ('Your name is ' + x + y)


^only works as far as asking last and first name in that order, however I cannot get the first and last name to print in that order.

Sorry if this is the wrong forum, couldn't really find any other place but I know a few of you here are programmers so why not try.


--------------------
zen by age ten times six hundred lifetimes
Light up the darkness.

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: hTx]
    #21300773 -

What does your line come back as after it's run?

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: TheMule73]
    #21300782 -

It asks the last name, then the first name, then goes red and says
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    print (raw_input('Last name?'))(raw_input('First name?'))
TypeError: 'str' object is not callable


--------------------
zen by age ten times six hundred lifetimes
Light up the darkness.

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: hTx]
    #21300873 -

Okay, I got it down pretty crudely..

question = "Last name:"
question1 = "First name:"
print (question)
answer = raw_input()
print (question1)
answer1 = raw_input(question1)

print ("Your name is " + answer1 + answer + "!")
     
Works out, however, for some reason it asks for the first name twice..

EDIT: SOLVED!!!

question = "Last name:"
question1 = "First name:"

answer = raw_input(question)

answer1 = raw_input(question1)
print ("Full name:" + answer1 + answer)

     


--------------------
zen by age ten times six hundred lifetimes
Light up the darkness.

Edited by hTx (02/19/15 08:21 PM)

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: hTx]
    #21300940 -

Nice dude! I've just started teaching myself Python too. I don't know much about programming but I work with R quite a bit. I think Python will be useful down the road.


--------------------

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: hTx]
    #21301116 -

I'm a big Python fan but I'm not as familiar with Python 2.x, which has some differences in how printing and input are done among other things. 3.x is not backwards compatible with 2.x and it's probably better to learn 3.x, unless you really need to deal with old code.

Python 2: print ""
Python 3: print("")

Basically the error you got means that it looks like you're trying to take a string object and call it as if it were a function.
Quote:
print (raw_input('Last name?'))(raw_input('First name?'))



The "(raw_input('Last name?'))" part resolves to a string containing whatever the input was, then Python tries to call this string object as if it were a function, supplying "raw_input('First name?')" as a parameter. If that had succeeded, it would then have tried to print the result.

Extras: Filter Print Post Top
Re: Python Programmers HELP?! [Re: psi]
    #21301312 -

We have a code tag on the shroomery. Anyhow, here is my crack at the question.
I'm more familiar with python2

Code:

#!/usr/bin/env python


def main():
"""
Ask the user for their name. And thanks them upon completion.
"""
print "Papers Please"
print "----------------------------"
first_name = raw_input("First Name: ")
last_name = raw_input("Last Name: ")
print "----------------------------"
print "Thank you, %s %s" % (first_name.title(),last_name.title())


if __name__ == '__main__':
main()




--------------------

Calico Kahlia come tell me the news
Calamity's waiting for a way to get to her
Rosy red and electric blue
I bought you a paddle for your paper canoe

Say you'll come back when you can
Whenever your airplane happens to land
Maybe I'll be back here too
It all depends on what's with you

Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: Unfolding Nature Unfolding Nature: Being in the Implicate Order   Myyco.com Golden Teacher Liquid Culture For Sale


Similar ThreadsPosterViewsRepliesLast post
* Programmers of the shroomery Acaterpillar 367 8 12/04/11 11:14 PM
by akira_akuma
* C++ question any programmers out there? Gainer 1,174 10 06/12/08 11:30 PM
by DieSpectra
* Python + Tkinter help citricacidx 346 1 02/01/11 08:50 PM
by citricacidx
* How come girls don't like Monty Python?
( 1 2 all )
crackawebsta 6,083 24 02/15/10 07:37 PM
by crackawebsta
* Python Eats Family Dog Mickalopagus 1,092 6 02/28/08 07:09 PM
by TryptoFan
* I am thinking of buying a Ball Python or a Corn snake
( 1 2 3 all )
quarkyquasar 6,795 46 10/25/04 06:40 PM
by Kinderfeld
* My Python .... JettaJay 1,261 9 12/29/04 02:53 PM
by JettaJay
* Ball Python? smac1009 1,038 9 09/15/09 08:33 AM
by Fort Mushroom

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: Entire Staff
509 topic views. 4 members, 884 guests and 156 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2026 Mind Media. Some rights reserved.

Generated in 0.028 seconds spending 0.008 seconds on 16 queries.