This page is intended for anyone who does or doesn't want to learn programming but needs to use it and doesn't know how it works. I understand that programming is very difficult to learn at first, due to its technical nature, and the fact that it's a new concept to the average computer user, so this page is designed for the people that need a kickstart to programming but can't handle the formal method of learning it.
We have other suggestions for python tutorials on the Programming page but if the other tutorials don't work for you THIS PAGE may the the tutorial you need as it uses a different approach.
Hello World
print "hello world"
Who Goes There?
print "Halt!"
user_reply = raw_input("Who goes there? ")
print "You may pass,", user_reply
Count to 10
a = 0
while a < 10:
a = a + 1
print a
Password (a # sign in Python is a comment, it tells extra information (in regular English) without affecting how the program runs)
password = "no password"
# note that != means not equal
while password != "typepasswordhere":
password = raw_input("Password: ")
print "Welcome in"
Sum Program
a = 1
s = 0
print 'Enter Numbers to add to the sum (positive or negative)'
print 'Enter 0 to quit.'
while a != 0:
print 'Current Sum:', s
a = input('Number? ')
s = s + a
print 'Total Sum =', s
High / Low Guessing Program
number = 10
guess = 0
while guess != number:
guess = input("Guess a number: ")
if guess > number:
print "Too high"
elif guess < number:
print "Too low"
print "Just right"
Even / Odd Program
number = input("Tell me a number: ")
if number % 2 == 0:
print number, "is even."
elif number % 2 == 1:
print number, "is odd."
else:
print number, "is a decimal."
Average Numbers Program
sum = 0.0
print "This program will take several numbers then average them"
count = input("How many numbers would you like to average: ")
current_count = 0
while current_count < count:
current_count = current_count + 1
print "Number", current_count
number = input("Enter a number: ")
sum = sum + number
print "The average was:", sum / count
Temperature Converting Program
def print_options():
print "Options:"
print " 'c' convert from celsius"
print " 'f' convert from fahrenheit"
print " 'q' quit the program"
def celsius_to_fahrenheit(c_temp):
return 9.0 / 5.0 * c_temp + 32
def fahrenheit_to_celsius(f_temp):
return (f_temp - 32.0) * 5.0 / 9.0
choice = "p"
if choice == "p":
print_options()
while choice != "q":
if choice == "c":
temp = input("Celsius temperature: ")
print "Fahrenheit:", celsius_to_fahrenheit(temp)
elif choice == "f":
temp = input("Fahrenheit temperature: ")
print "Celsius:", fahrenheit_to_celsius(temp)
choice = raw_input("option: ")
Many people don't exactly know what programming can do for them. So here's a summed up answer: it manipulates data through a series of easy logic. Here's the example:
If there are exactly 20 people in a room, for each member in the room, announce to each member to "Take a seat.".
This may not seem like programming at first, since it's plain English! And that's partially correct: this isn't formal programming. If I threw this statement on a computer, I'm sure I'd get tons of errors. However, if I told a human to do this, would that human understand it? Yes, of course. This is what's known as pseudocode, and it's probably the most effective way of learning how to program in any language.
So then how is this pseudocode related to regular code? Well, let's find out. Let's take each part of my statement apart.
That's as low-level thinking as I can get. Basically, I've just explained what we process so quickly in our brains so that we can turn it into computer compliant code. So if I wanted to write this in computer compliant code, it might look like:
if len(the_room) == 20:
for each_member in the_room:
each_member += " has been told to take a seat"
The_room is also a variable since the room has members inside it, so its length varies and members vary. Each_member seems to refer to a name of the person in the room. So each_member is a new variable that varies every time the ensuing command finishes.
( The above example was written in Python. )
Let's get a little more how everything works.
The integer, as we should all know from math class, is any positve/neutral/negative whole real number. 1 is an integer, 55 is an integer, 0 is an integer, -10 is an integer.
The float is any number that's real. 1.9999 is a float, 0.000 is a float (as long as there's a dot), -2.75 is a float.
If I said x = 10, what is x in terms of integers or floats? It's an integer.
Other Tutorials