Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 10th, 2007, 3:43 PM   #21
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

ok that made absolutely no sense

Anyways I need to stop programming since the computer I had the command line on, I had to blow the hard drive away because of problems. The computer had originaly came with 95 but got upgraded with 98SE. The 98SE CD suddenly decided not to work (I checked it before I re formatted the computer and it worked). Then I tried XP. But XP is just to big and causes the computer to freeze right after I log in. This means I am going to have trouble reformating again, even though I got 98SE loaned to me.

If you didn't understand any of that you will know why I say, I HATE COMPUTERS lol
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 10th, 2007, 4:41 PM   #22
MiKuS
Hobbyist Programmer
 
Join Date: Jun 2007
Posts: 129
Rep Power: 2 MiKuS is on a distinguished road
Re: I'm a Beginner

install xubuntu

http://www.xubuntu.org/
MiKuS is offline   Reply With Quote
Old Dec 11th, 2007, 8:48 PM   #23
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

how?? it freezes when I press the start button and I am having trouble with safe mode. (I tell it to run safe mode and a list of commands pop up, then it freezes.)
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 12th, 2007, 10:07 AM   #24
somehollis
Programmer
 
somehollis's Avatar
 
Join Date: May 2006
Location: Memphis, TN
Posts: 31
Rep Power: 0 somehollis is on a distinguished road
Send a message via AIM to somehollis
Re: I'm a Beginner

Quote:
Originally Posted by Chuckiferd View Post
how?? it freezes when I press the start button and I am having trouble with safe mode. (I tell it to run safe mode and a list of commands pop up, then it freezes.)
Xubuntu isn't a piece of windows software; it's an Ubuntu-linux derived operating system that is supposed to work well with older / slower hardware. Python comes preinstalled, so it would make continuing your education a simple matter.
somehollis is offline   Reply With Quote
Old Dec 12th, 2007, 4:54 PM   #25
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

but I can't even go online to install it. Or get into windows long enough to put in a disk I burn from this computer.

Anyways could someone tell me if this would work. This is my very first original program, even though it is just a single loop.

For i in b
  print '%d*%d=%d' % (i,b,i*b)
    i= range (1,13)
    b= range (1,11)
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 12th, 2007, 6:29 PM   #26
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: I'm a Beginner

No it would not. Let's look at what you're trying to do:

1) First Line

For i in b

Commands are case sensitive. For is not a valid command. for is the command you're looking for.

It assigns i to each element in b sequentially. But what's b? You have not defined it at this part of the program. Remember that a program executes one line at a time, and at this point in time, there is no value for b.

Later you do give a value to b: b= range (1,11). If you want to stay consistent with this, your first line becomes:

for i in range (1,11)

Then you need a colon at the end to denote the start of a new block. Everything that proceeds the colon, and is indented, will execute for each element in b.

for i in range(1, 11):
    # Do some stuff here for each element in range(1, 11)

It's important to note... since b is range(1, 11), Python will convert this to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].

So the same code could also be written as:

for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    # Do some stuff here for each element in range(1, 11)

But that's not as modifiable.

2) Looking at your Second Line

print '%d*%d=%d' % (i,b,i*b)

You're trying to output i*b and b, but b is a list of elements 0 through 10. That's an invalid operation. You can't multiply numbers by lists.

It looks like you're trying to do something like multiply 1 to 11 by 1 to 13 like a grid. You'll need to understand for loops a bit better before you can do that.

3) Using a for loop

If we go back to my previously posted code, and modify it to print the number each iteration:

for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    print i

You get the output:

1
2
3
4
5
6
7
8
9
10

Which will be the same output for:

for i in range(1, 11):
    print i

If we extend this to make a loop within a loop, you'll get this:

for i in range(1, 11):
    for j in range(1, 11):
        print i, j

Which will output:
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
8 1
8 2
8 3
8 4
8 5
8 6
8 7
8 8
8 9
8 10
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9
9 10
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
10 10

You could then modify this to do the multiplication grid you wanted.

Last edited by Sane; Dec 12th, 2007 at 6:50 PM.
Sane is offline   Reply With Quote
Old Dec 14th, 2007, 9:09 PM   #27
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

I think I will continue "paper" programming and run them once the computer is up and running
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 18th, 2007, 2:18 PM   #28
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

I have decided to try making a text adventure game. This seems easy as it is simply a bunch of documents that you open by moving in directions. Of course a combat system is way beyond me

here is what I wrote, I know I am wrong but here is what I mean to do

1=Beginning of yellow brick road
2=Middle of yellow brick road
3=End of yellow brick road, yeah! you just played my first game and wasted 10 seconds of your life
#level= 1 2 3#
        east= %d + %d = %d  % (1, the number you are currently on, the solution)

So if you see what I am trying to do please walk me throught what i need to do to create this.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 18th, 2007, 6:09 PM   #29
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: I'm a Beginner

Quote:
Originally Posted by Sane View Post
You can't multiply numbers by lists.
Actually you can, and the result is sensible:

>>> print '%s' % ([1,2] * 2)
[1, 2, 1, 2]
titaniumdecoy is offline   Reply With Quote
Old Dec 18th, 2007, 6:10 PM   #30
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: I'm a Beginner

Quote:
Originally Posted by titaniumdecoy View Post
Actually you can, although the result might not be what you would expect:

>>> print '%s' % ([1,2] * 2)
[1, 2, 1, 2]
>>> print '%s' % [1,2] * 2
[1, 2][1, 2]
Deters from my point. But yes...


@Chuckiferd:

As far as a "proper" implementation of this idea can go, it would take some familiarity with Python.

For a personal learning exercise, I'd say just go with if, print, and input statements. Those three things in conjunction could make your game.

If you want to actually do visible movement, you won't be able to do it this way...


A print statement outputs something to the user:
print "You Are At The Beginning Of A Yellow Brick Road"

The input function gets something from the user:
choice = input("""What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: """)

That will output to the screen:
Quote:
What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: <space for typing>
And prompt the user to type a number where I wrote <space for typing>. After this line executes, the variable "choice" will equal the number the user selected.

An if statement can branch your program in an alternate direction, according to the value of a variable. So if we wanted to do one thing if the user selected "1", and another if the user selected "2", it's as simple as:

if choice == 1:
    # The user selected 1. Do something here.
elif choice == 2:
    # The user selected 2. Do something different here.
else:
    # The user did not select 1 or 2. Make it default to option #3. And do something else!

These three things, "if", "print", and "input" could be combined to make your text adventure:

Python Syntax (Toggle Plain Text)
  1. print "You Are At The Beginning Of A Yellow Brick Road"
  2.  
  3. choice = input("""What do you want to do?
  4. 1) Walk In To The House
  5. 2) Pick Up A Penny Off The Ground
  6. 3) Twiddle Thumbs
  7. Enter A Number: """)
  8.  
  9. print
  10.  
  11. if choice == 1:
  12.  
  13. print "The house feels warm and welcoming, but a strange man (most likely the owner) is sitting on the couch looking very frightened of your presence."
  14. choice = input("""What do you want to do?
  15. 1) Quickly Apologize And Leave
  16. 2) Ask Him Who's House This Is
  17. 3) Enter Battle Mode!
  18. Enter A Number: """)
  19.  
  20. print
  21.  
  22. if choice == 1:
  23. print "etc"
  24. elif choice == 2:
  25. print "etc etc"
  26. else:
  27. print "etc etc etc"
  28.  
  29. elif choice == 2:
  30.  
  31. print "The penny was actually a piece of radioactive material. You sit there shocked and confused, and die 30 years later."
  32.  
  33. print "Game Over"
  34.  
  35. else:
  36.  
  37. print "While you're twiddling your thumbs, you notice there's a penny on the ground! But before you can pick it up an old man comes out of a house and snatches it from you, then heads back inside."
  38. choice = input("""What do you want to do?
  39. 1) Follow The Man Into His House
  40. 2) Continue Walking Down The Road
  41. 3) Continue To Twiddle Thumbs
  42. Enter A Number: """)
  43.  
  44. print
  45.  
  46. if choice == 1:
  47. print "etc"
  48. elif choice == 2:
  49. print "etc etc"
  50. else:
  51. print "etc etc etc"

Get it?

Here's an example of me running the programming, and playing the adventure:

Quote:
You Are At The Beginning Of A Yellow Brick Road
What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: 1

The house feels warm and welcoming, but a strange man (most likely the owner) is sitting on the couch looking very frightened of your presence.
What do you want to do?
1) Quickly Apologize And Leave
2) Ask Him Who's House This Is
3) Enter Battle Mode!
Enter A Number: 3

etc etc etc
It will get messy really quick. But I think you'll learn something. You will need to do some really basic stuff to get comfortable with Python.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Problem proudnerd C++ 16 May 18th, 2006 6:48 PM
call of a beginner web_master HTML / XHTML / CSS 34 Dec 6th, 2005 12:08 AM
function help for a beginner melee28 C 6 Sep 5th, 2005 9:45 AM
what open source code is good to read for a beginner? linuxpimp20 Other Programming Languages 22 Aug 30th, 2005 3:01 PM
Beginner program problem (else if) Hadrurus Java 13 Aug 14th, 2005 7:07 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC