[TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32) +---- Thread: [TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! (/showthread.php?tid=1516) |
[TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! - nevets04 - 10-14-2009 PYTHON FOR BEGINNERS Chapter 1: Intro Chapter 2: Your first python script Chapter 3: Magic eight ball Chapter 4: Calculator INTRO This tutorial is directed to people learning python, and that already have python installed on their computer and know how to execute a script. If you don't, download python from python.org. If you are on Linux or mac, you should already have python and to execute the script you made in text edit and saved as a .py, go into terminal and type Code: python scriptname.py YOUR FIRST PYTHON SCRIPT The Print Command: This simple but useful function displays text on the screen Code: print "Hello there" Quote:Hello there Variables: Used to store information, variables can be very helpful Code: a = "hello" Code: print a Quote:hello raw_input: This function is used to take input from the user of your program Code: raw_input("Type Something: ") Quote:Type Something:This function isn't very useful without it meaning something, so to do this we will allow a variable to store the information the user inputs Code: x = raw_input("Type Something: ") Quote:Type Something:This may look the same, however, adding the "x =" makes whatever the user types equal to x Your first python script: putting everything you just learned together we will make our first script Code: x = raw_input("Type Something: ") MAGIC EIGHT BALL import: This is used to import moduels A moduel is basically another script For your second project we will be using the moduel "random" Code: import random.py Moduel Fuctions: Different moduels have different fuctions For this project, we will be using the choice fuction Code: random.choice Strings: Now we need make a string that random.choice will choose a variable or quote from from Code: array = ['a','b','c','d','e','f'] random.choice: Next we will make random.choice choose a random variable from the array, which was our string Code: random.choice(array) Magic Eight Ball: Code: import random CALCULATOR Defining your own fuctions: you can use this to make your own functions Code: def add(a,b): Math symbols: The basic sybols for math in python are +, -, *, and / Code: x = 2 + 2 Quote:4 While loop: The while loop is used to make your program run a certain amount of times, or an unlimited amount of times Code: x = 0 Quote:hi if: This command means if this is true, do this Code: x = 1 Quote:hiThe reason there are two equal signs is so there are more options than just =, <, or >. Since you can use two sybols, you can do many more things. For example do not equal to Code: != Calculator: Code: print "1) Addition" RE: [TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! - Mr.FeellingLeSS - 10-20-2009 nice you are realy a supporting face around here RE: [TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! - Codine - 10-20-2009 Thanks for this, i'm currently learning python.. RE: [TUT] Python Tutorial, Learn To Make Many Different Projects And Fuctions! - nevets04 - 10-26-2009 ~~~~~bump~~~~~ |