Friday, March 2, 2012

A little Intro to Python

Today I had some spare time, So I decided to begin teaching myself python, below is a pointless little program I wrote to get some practice with IF's, Whiles, Prints, and functions. I am enjoying the python language so far, it is quite interesting, and fun!.

##################################################################################



#!/usr/bin/env python

#Simple Yes or No
#By Anthony Boccia
#Learning Some Python

#This is the yes or no question function
def question():
print ('Is this Right? Yes or No ( Exit - to Quit program)? ')
answer=raw_input()

while answer != 'Yes'  and answer !='No' and answer !='Exit':  #Check for user errors
print('\nERROR: Enter Yes or No ( Exit - to Quit program) ""Case Sensitive""\n')
print ('Is this Right? Yes or No? ')
answer=raw_input()

return answer #Return the user input to the main program

#This is the main program
answermain  = 0
while answermain != 'Exit':

answermain = question()

if answermain == 'Yes' or answermain =='No':

#Check the returned value and output the proper message based on the value of answermain
if answermain == 'No':
print ('\nYou said ' + answermain + ' Very Well then, it is ' + answermain + 't right\n') #noticed how i used the variable again and added a t for not? Clever or lame? you Decide

elif answermain == 'Yes':
print ('\nYou said ' + answermain + ' Very Well then, it is right\n')
else:
print ('Good' + 'bye!') #Message Printed upon Exit by user which kills loop in backend



##################################################################################

Thats all for now, Cheers!