Jump to content
SubSpace Forum Network

Recommended Posts

Posted (edited)

Since I don't really have a blog account, and I didn't want to fill up one of my other topics I've made in the HS's Zone Development forum section with off-topic chat, thought I'd share here.

 

Been learning Python for a couple of days. Over the past 5 years or so I've tried to pick up various languages through online tutorials, and eventually give up after a few days from pure confusion and boredom. I really think I've found the perfect online tutorial (it's also a published book, and it's 100% free: view and/or download at http://inventwithpython.com/ )

 

Why you ask? Because throughout this tutorial I've noticed that in the notes I'm writing down, I tend to make a lot of visual diagrams, and so does he - like below, or because python is just that great of a language to begin from. The first language I picked up was HTML, that was when I was 14, and over the past 5 7 (math fail! gogo gadget HS Dropout!) years I've tried picking up C, C++, and C# multiple times, and Java once (I had to stop learning Java because I had important things going on)

http://img195.imageshack.us/img195/5624/10348586.png

 

I know that's a very basic code line, I'm just using it as an example of what I mean by visuals. I've noticed that my learning ability was hampered when I was in school, because none of my teachers did anything like this. Pure text can sometimes get me confused when I'm learning (I won't have any problem writing it though - I'm a great writer, and I think I'll be great when writing programs once I understand).

 

I've written 7 pages of little notes, pictures, diagrams and definitions. I feel really good about myself right now - more so than I have in a long time (while sober, atleast). I'm impressed with myself. I'm sure this is practically nothing to you guys, but trust me I have big issues with self esteem. I never really thought I could get this far. Right now, I'm entering Chapter 8 - that's about 40% complete with the tutorial.

 

When I'm done with this, which should probably be a couple weeks because I've taken a peek at the coming chapters and they look a bit rough, plus I'm constantly taking notes to make sure I remember and can look back and study it easily, I think I'm going to look through the different .py scripts in \asss\asss-1.4.4\scripts and see if I can make very detailed comments so I can see what I don't understand and what I do understand. I think it would be a good exercise. I've taken a quick glance and noticed that I actually understand a very very large portion of what I saw, and I'm sure if I sat down and tried to read it a bit more in-depth I could figure it out.

 

If anyone's got any other exercises they do/have done as they were going along, please feel free to share. I know a lot of you have great programming skills, and we all started like this at one point.

 

So far what I've learned and fully understand:

  • Integers and Floating Point Numbers
  • Expressions
  • Values
  • Operators
  • Evaluating Expressions
  • Storing Values in Variables
  • Flow of execution
  • Strings
  • String concatenation
  • Data types (such as strings or integers)
  • Using IDLE to write source code.
  • Saving and running programs in IDLE.
  • The print() function.
  • The input() function.
  • Comments
  • Capitalizing variables
  • Case-sensitivity
  • Overwriting variables
  • import statements
  • Modules
  • Arguments
  • while statements
  • Conditions
  • Blocks
  • Booleans
  • Comparison operators
  • The difference between = and ==.
  • if statements
  • The break keyword.
  • The str() and int() functions.
  • The random.randint() function.
  • Using print()'s end keyword argument to skip newlines.
  • Escape characters.
  • Using single quotes and double quotes for strings.
  • The time module.
  • The time.sleep() function.
  • The return keyword.
  • Creating our own functions with the def keyword.
  • The and and or and not boolean operators.
  • Truth tables
  • Variable scope (Global and Local)
  • Parameters and Arguments
  • Flow charts
  • ASCII art
  • Designing our game by drawing a flow chart before programming.

 

That's all for now!

Edited by Xog
Posted
Heh I just started of coding without any tutorial/whatnot and kept hammering at it until it did something. Aka drawing pretty interfaces in Visual Basic 6
Posted

Read previous code, implement it into your code - find out exactly what is happening. The longer you spend doing it, the more experienced you become and so on..

 

 

I've decided to not write any of my own code until I'm completely done with the 19 chapter tutorial. I think messing around with code before I understand everything is what started to get me confused and led to me quitting, so I'm going to hold off on it.

Posted

I learned to code by indulging myself into something over my head and looking up how to do everything until I had a finished product. Although I may have made mistakes, the advantage is that I got experience applying concepts to a real project. Besides, the debugger tells me if I do something wrong :D .

 

You said that you weren't going to code anything until you finish chapter 19...

 

I would advise that you at least do something with your new knowledge. It will help reinforce what you've learned, and will give you motivation to learn new and more advanced concepts.

Posted (edited)

I learned to code by indulging myself into something over my head and looking up how to do everything until I had a finished product. Although I may have made mistakes, the advantage is that I got experience applying concepts to a real project. Besides, the debugger tells me if I do something wrong smile.gif .

 

You said that you weren't going to code anything until you finish chapter 19...

 

I would advise that you at least do something with your new knowledge. It will help reinforce what you've learned, and will give you motivation to learn new and more advanced concepts.

 

Well, in the tutorial we're given new program source for simple games.. I do change stuff up to see if different things work, once I'm finished with the chapter. I know what you mean though.

 

If you really think I should just start stop and write a little program just for the experience, give me an assignment for something (like a test I suppose) based on what I've learned so far and I'll try and do it. When I'm done I'll continue the tutorial

 

Preferrably one that deals with if, while, else, or, and, and def

 

"Write a program that will.."

Edited by Xog
Posted

Well you my as well just write one program that covers all that you've covered. No point in going back to write one program for each chapter.

 

What LYNX said would be a good idea.

 

Alright then! Here we go.

 

Start time: 7:30 PM

Posted

Preferrably one that deals with if, while, else, or, and, and def

 

"Write a program that will.."

Programs don't usually 'deal with' such instructions... It's how you implement an idea that defines what instructions will be used.

Also, if you manage to make a (useful) program that doesn't use any IF's... congratulations (using useless for's or while's to make an 'if' condition doesn't count blum.gif )

Posted (edited)

Post your code when you're done, we'll give feedback.

 

Pausing at 8:00. New show coming on TV, and I'm getting a bit confused. I really want to get back to it though, but gf wants company blum.gif

 

It's just one little part that's messing me up. I don't want to ask questions yet though!

Edited by Xog
Posted (edited)

lol rootbear why the hate !

 

 

anyways, I give in. Time: 11:19. I need some help. I feel like such an idiot. What am I missing here?

 

Total hours wasted in confusion: 1hr. 30 minutes. Took me about 20 to write the whole thing, but I just got confused and can't figure out what I'm doing wrong!

 

#Simple Lotto program
import random
import time

picked = 0


#Greeting
print('''Hello! Welcome to Xog\'s Lotto Application. Thank you for taking the time to test my application out.
To play this Lotto game, I want you to pick three numbers from 1 through 5.''')

#Waits for 2 seconds.
time.sleep(2)

#Getting to know you
print('Don\'t get hasty! First, I want you to tell me your name. Please type it in and press Enter.')
name = input()
print('Hello, ' + name + ', my name is Xog.')

#Number picking
number = random.randint(1, 5)
print('Okay, now that we know eachother a little bit, I think it\'s time we begin.')


while picked < 3:
print('Please pick a number from 1 through 5.')
playerPicked1 = input()
playerPicked1 = int(playerPicked1)
picked = picked + 1
#
print('Pick your second number, between 1 and 5, that you did not pick.')
playerPicked2 = input()
playerPicked2 = int(playerPicked2)
picked = picked + 1
#
print('Pick your third and last number, between 1 and 5, that you did not pick.')
playerPicked3 = input()
playerPicked3 = int(playerPicked3)
picked = picked + 1


#while picked < 3:
#	print('Pick your second number, between 1 and 5, that you did not pick.')
#	playerPicked2 = input()
#	playerPicked2 = int(playerPicked2)
#picked = picked + 1

#if picked < 3:
#	print ('Pick your third and last number, between 1 and 5, that you did not pick.')
#	playerPicked3 = input()
#	playerPicked3 = int(playerPicked3)
#picked = picked + 1

if playerPicked1 or playerPicked2 or playerPicked3 == number:
number = str(number)
print('The lotto number was ' + number + '! Congratulations! You\'ve just won $500 Hyperspace Dollars!')
time.sleep(3)
print('Well.. Okay, maybe not the money.')

if playerPicked1 and playerPicked2 and playerPicked3 != number:
number = str(number)
print('Sorry, the last number was ' + number + '.')

## if playerPicked1 != number:
##	number = str(number)
##	print('Sorry, the last number was ' + number + '.')

##if playerPicked2 != number:
##	number = str(number)
##	print('Sorry, the last number was ' + number + '.')

##if playerPicked3 != number:
##	number = str(number)
##	print('Sorry, the last number was ' + number + '.')

print('Thanks for playing Xog\'s lotto!')

 

the return after the name is:

Okay, now that we know eachother a little bit, I think it's time we begin.

Please pick a number from 1 through 5.

1

Pick your second number, between 1 and 5, that you did not pick.

2

Pick your third and last number, between 1 and 5, that you did not pick.

4

The lotto number was 3! Congratulations! You've just won $500 Hyperspace Dollars!

Well.. Okay, maybe not the money.

Sorry, the last number was 3.

Thanks for playing Xog's lotto!

 

Not making sense!!!

Edited by Xog
Posted (edited)

xog, what programming language, because if it's java, i see a bunch of errors there

 

Also: for simplification, i'd use an array for Playerpicked. would eliminate a lot of programming, and also, that while loop is unneeded the way you have it picked now.

 

 

as for what i can see:

change

while picked < 3:
       print('Please pick a number from 1 through 5.')
       playerPicked1 = input()
       playerPicked1 = int(playerPicked1)
       picked = picked + 1
       #
       print('Pick your second number, between 1 and 5, that you did not pick.')
       playerPicked2 = input()
       playerPicked2 = int(playerPicked2)
       picked = picked + 1
       #
       print('Pick your third and last number, between 1 and 5, that you did not pick.')
       playerPicked3 = input()
       playerPicked3 = int(playerPicked3)
       picked = picked + 1

 

TO

//Initialize an array of playerpicked with a size of three; somewhere before here.
String input = null;

while picked < 3:
       print('Please pick a number, between 1 and 5. (' + str(picked+1) + ')')
       input = input()
       playerPicked[picked] = int(input)
       picked = picked++
       #
picked = 0

 

also change the whole ending to:

 

Boolean win = null;
while picked < 3
       if playerPicked[picked] == number:
               win = true;
//endwhile

number=str(number);

if win == true:
then
               print('The lotto number was ' + number + '! Congratulations! You\'ve just won $500 Hyperspace Dollars!')
               time.sleep(3)
               print('Well.. Okay, maybe not the money.')

else
       print('Sorry, the last number was ' + number + '.')
//endif

(I think thats the correct syntax, not sure what language you are using)

Edited by rootbear75
Posted (edited)

Okay, next time you should read the other posts. I've displayed what I've learned. A lot of the stuff you put in, I haven't learned yet. I appreciate the help, but it didn't really help. :/

 

For other clarification, I did try using a list (i think this is an array in whatever language you were using)

 

PLAYERPICKS = [playerPicked1, playerPicked2, playerPicked3]

for each one I could use 0, 1, and 2 instead of typing it all out. I haven't read far into it the list part yet, it's actually the chapter I'm on right now, but I haven't begun because I decided to write this. That's all I know about lists/arrays from a glance at the chapter.

 

The reason I changed it back, is because I kept getting errors. I realized what I did wrong after I changed everything. I forgot the = after the PLAYERPICKS. I erased that part last, and just as I deleted it, I just about smacked my monitor.

 

There's a lot of other variations I've tried with everything below the name/getting to know u part, but they aren't included because I erased them instead of putting the comment markers (#) in python. The ones with comments you see now is the last one I tried.

Edited by Xog
Posted (edited)

Hey, that seems like a good first try. Here are some points I'd pick up on first:

 

# Getting to know you
userName = raw_input("Hi, don't get too hasty, enter your name: ")
print "Hi there, " +name +" it's nice to meet you! Let's move on..."

# here is an example of a sentinal controlled iterator,
# which will save you writing out the same code over and over

counter = 0 # create an 'empty' variable
userPicks = [] # create a list to store the users lottery picks
while counter < 5:
# grab a number from the user, store it as an int
pickedNumber = int(raw_input("Please enter a number: "))
# append that to the list we created earlier
userPicks.append(pickedNumber)
# just to highlight the use of sentinal controlled values
print "The counter is currently " +str(counter)
# iterate the sentinal by 1
counter += 1

 

You can also use the same methods above, but generating another instance of random.randint() each time. You can then compare the contents of both lists, the easiest way to do this is to sort both lists - then compare them. to do this, you'll need to refer to the Python documentation (make use of the interpreter if you're struggling.)

 

ps. Try not to pass col. 79 when writing any code.

 

This is my rant section... Whenever you're learning a new language, try to conform by it's standards. Python is friendly, but others aren't - languages like Java/Python/Ruby will make you lazy. Try not to pick up on bad habits early. :)

 

Edited by Lynx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...