Sunday, April 17, 2011

Rescue Me

Monday, April 11, 2011

Python - Sort list and how they are out of order

print "This program takes 10 numbers, and tells you how many are out of order, and how they are out of order."
print "Now please enter your numbers."

list1 = []
times = 10

while times > 0:
   num = float(raw_input())
   list1.append (num)
   times = times - 1
   del num

incorrect = 0
times2 = 0

while times2 < 9:
   if list1[times2+1] < list1[times2]:
       print list1[times2], "appears before", list1[times2+1]
       incorrect = incorrect + 1
   times2 = times2 + 1

  
print "this many are out of order", incorrect

times3 = 0
times4 = 0

while times3 < 9:
   while times4 < 9:
      if list1[times4] > list1[times4+1]:
         list1[times4], list1[times4+1] = list1[times4+1], list1[times4]
      times4 = times4 + 1
   times3 = times3 + 1
   times4 = 0
print list1

raw_input()

Python - Guitar fret and string to note, or note to string and fret - by Shawn Mccombs

string =[["No data for string 0"],
         ["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","string 1"],
         ["B","C","C#","D","D#","E","F","F#","G","G^","A","A#","B","C","C#","D","string 2"],
         ["G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","string 3"],
         ["D","D#","E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","string 4"],
         ["A","A#","B","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","C","string 5"],
         ["E","F","F#","G","G#","A","A#","B","C","C#","D","D#","E","F","F#","G","string 6"]
        ]

frets = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

print "To find out which note you'r playing, press 1."
print "To find out where all of a note is, press 2."

which = raw_input()

if which == "1":
   print "Which string? 1, 2, 3, 4, 5, 6?"
   stringnum = int(raw_input())
  
   print "Which fret? 0 - 15"
   fret = int(raw_input())

   print string[stringnum][fret]
  
if which == "2":
   print "Which note? A, A#, B, C, C#, D, D#, E, F, F#, G, G# ?"
   note = raw_input()
  
   print "String 1."
  
   loop = 0
  
   while loop < 15:
      if note == string[1][loop]:
         print frets[loop]
      loop = loop + 1
    
   print "String 2."
  
   loop = 0
  
   while loop < 15:
      if note == string[2][loop]:
         print frets[loop]
      loop = loop + 1

   print "String 3."
  
   loop = 0
  
   while loop < 15:
      if note == string[3][loop]:
         print frets[loop]
      loop = loop + 1

   print "String 4."
  
   loop = 0
  
   while loop < 15:
      if note == string[4][loop]:
         print frets[loop]
      loop = loop + 1

   print "String 5."
  
   loop = 0
  
   while loop < 15:
      if note == string[5][loop]:
         print frets[loop]
      loop = loop + 1

   print "String 6."
  
   loop = 0
  
   while loop < 15:
      if note == string[6][loop]:
         print frets[loop]
      loop = loop + 1

raw_input()

Python - Cents back?

print "Please enter your cents."
cents = int(raw_input())

q = cents / 25
cents = cents % 25
d = cents / 10
cents = cents % 10
n = cents / 5
cents = cents % 5
p = cents / 1



print q, "Quarters", d, "Dimes", n, "Nickles", p, "pennyes"
raw_input()

Python - Min and Max

print "This program takes 10 numbers, and tells you the smallest and the biggest."
print "Now please enter your numbers."

list1 = []
times = 10

while times > 0:
   num = float(raw_input())
   list1.append (num)
   times = times - 1
   del num

which = 0
current = list1[0]

current2 = list1[0]

while which < 9:
  
   if current > list1[which+1]:
      current = list1[which+1]
    
   if current2 < list1[which+1]:
      current2 = list1[which+1]
  
   which = which + 1

print "The smallest is:", current

print "The biggest is:", current2

raw_input()

Python - Average and Sum

print "This program takes a list of any number, then displays the sum, and average of them."
print "Now please enter your numbers followed by a x."

listofnums = []
loop = 1

while (loop == 1):
   enterednum = raw_input()
   if enterednum == "x":
      loop = 0
      break
   else:
      listofnums.append (float(enterednum))
      del enterednum

print "here are all the numbers you entered."

for thelist in listofnums:
   print thelist
  
thesum = sum(listofnums)

numofvar = len(listofnums)
average = thesum / numofvar

print "The sum is:", thesum
print "And the average is:", average

raw_input()

Python - Miles to Kilometers

print "This program takes miles, and changes it to kilometers."
print "Now please input Miles."

kilo = 1.609344
miles = float(raw_input())

if (miles > 0):
   answer = miles * kilo
   print "So", miles, "x", "1.609344 =", answer, "Kilometers"
   print "Now see that wasn't that hard. :)"
else:
   print "0 is 0"
   print "Good bye!"

raw_input()