![]() |
Need help with python
Hi guys.
Just wondering if someone would be kind enough to help me with something I'm stuck on. I have 4 small programs to write in python. Each one gets progressively harder. I've never programmed in python before and was sort of trying to learn on an online tutorial. It didn't help much! lol Anyway, I've completed the first one, and now I'm stuck on the second one. I've tried for over 2 hours to figure this out and I can't. All this code looks like a bunch of letters and characters that are in a certain order to make the code, but I don't know why. Can someone help a girl out with what the code would look like? :) Here is what I have to do: PROGRAM 2 - USING INPUT Write an algorithm for a program that would get (as input from the user), 2 string variables and 2 integer variables, then joins together and displays the combined strings, and finally multiplies the two numbers on a new line. Write, test and debug the program using Python. SAMPLE OUTPUT (not including author/program information) Input string 1? Billy Input String 2? Bob Input integer A? 23 Input integer B? 2 BillyBob 46 Thanks guys! |
Re: Need help with python
Getting string input is as simple as:
:
my_string = raw_input("Message Before String Input: ")Likewise, integer input is as simple as: :
my_integer = input("Message Before Integer Input: ")"raw_input" is a standard function, which is a part of Python, which will give you user input in the form of a string. "input" is also a standard function, which will give you user input in the form of an integer. As you may already know, a "string" is a series of characters, and an "integer" is a number. Adding together two strings uses the "+" operator. And adding together two integers also uses the "+" operator. :
my_added_string = my_string + another_stringHow handy is that!? Those are all of the pieces of the puzzle. Piece them together the right way and you should have it! Good luck! |
Re: Need help with python
That's the thing... this all still looks foreign to me. I'm not a programmer at all and I just can't grasp this stuff. This sucks cuz I have to do it. *sighs* Looks like I'm getting a 0.
|
Re: Need help with python
Well, you don't have to get a zero. I'm not writing the code for you, but I basically gave you every piece of the puzzle. It's just a matter of arranging things correctly.
Take your time reading a tutorial. Try running pieces of the code I gave you. Try different things and see what happens. Try taking a logical approach and step through each line to see exactly what's happening. When you write this program, think of it as if you're translating from one language to another. Just as English can be translated to Spanish, it can also be translated to Python, by finding out what commands and syntax (grammar) of Python match that of English. Look at it step by step, and figure out the Python for it. For example... given some English: :
my age is 45The equivilent of 'is' in Python is '='. The equivilent of telling the user something is 'print'. A difference, mathematically, is a minus b. That would give us the following Python code: :
my_age = 45Does that make sense? Try applying this to other things and concepts. See what you can get working. Work your way up to the other code I've been showing you. Post some attempts. Someone can give you more direction if you show that you've tried something. |
Re: Need help with python
This is useless. I'm ready to beat the computer.
I've already read tutorials on this. I'm just not a programmer. Here is what I have: :
my_string = raw_input("Billy: ") |
Re: Need help with python
You're getting there.
Let's look at what you've done: Line 1: :
my_string = raw_input("Billy: ")You might want to prompt the user with some more appropriate text. Maybe "Enter A String". :
my_string = raw_input("Enter A String: ")Line 2: :
my_integer = input("23: ")You might want to prompt the user with some more appropriate text. Maybe "Enter A Number". :
my_integer = input("Enter A Number: ")Line 3: :
my_added_string = my_string + Billy:
my_string2 = raw_input("Please Enter Another String: ")Line 4: :
my_added_integer = my_integer + 2Then... you also want to show the values to whoever's running the program. You can do that with "print". "print" outputs something to the screen. Like so: :
print my_added_stringTry looking at this code: :
number1 = 4Run that. See if it behaves how you expected. See if you can use what you've learned from that in your code. |
Re: Need help with python
BTW - here is my first project. I followed the tutorials and did it okay.
:
print "2+2 =",2+2 |
Re: Need help with python
Well, now I'm getting a subprocess error when opening Python telling me a firewall is blocking the connection. Funny, I don't have any firewalls installed. Well, I guess that's it until tomorrow. Thanks for trying to help, Sane.
|
Re: Need help with python
IDLE (The Python Code Writing Area) is being bitchy. It's sometimes like that.
Chances are you wrote a program that prompted you for some text. You ran the program, and never entered any text. You can fix that by closing it all, and reopening it again. Sometimes you have to do that with "ctrl + alt + delete" and ending all processes that are "pythonw.exe" and "python.exe". But that may be above your skill level. Sorry I could not help any more. Best of luck. |
Re: Need help with python
I know how to end a process. Funny thing is I'm actually a computer geek - just don't know anything about programming. Can't seem to grasp it. Oh well.
|
| All times are GMT -5. The time now is 3:35 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC