s_name="Tri Star University"
scores = [88.7,90.4,76.0,97.0,100.0,86.7] #integer array
average=0.0
for ctr in range(0,6,1): #computes total of scores
average+=scores[ctr]
average/=float(6) #computes the average
print "At ",s_name,", your class average is ",'%.2f' %average,"\n"
def pr_scores(scores):
print "Here are your scores:\n"
for ctr in range(0,6,1):
print '%.2f' %scores[ctr],"\n"
s_name="Tri Star University"
scores = [88.7,90.4,76.0,97.0,100.0,86.7] #integer array
average=0.0
pr_scores(scores) #Function call to print scores
for ctr in range(0,6,1): #computes total of scores
average+=scores[ctr]
average/=float(6) #computes the average
print "At ",s_name,", your class average is ",'%.2f' %average,"\n"
CLASS_NUM=6
def pr_scores(scores): #Function definition
print "Here are your scores:\n"
for ctr in range(0,CLASS_NUM,1):
print '%.2f' %scores[ctr],"\n"
s_name="Tri Star University"
scores = [88.7,90.4,76.0,97.0,100.0,86.7] #Integer array
average=0.0
pr_scores(scores) #Function call to print scores
for ctr in range(0,CLASS_NUM,1): #Computes total of scores
average+=scores[ctr]
average/=float(6) #Computes the average
print "At ",s_name,", your class average is ",'%.2f' %average,"\n"
NUM_TEMPS=10
temps=[]
#Adding values into temps variable
temps.append(78.6)
temps.append(82.1)
temps.append(79.5)
temps.append(75.0)
temps.append(75.4)
temps.append(71.8)
temps.append(73.3)
temps.append(69.5)
temps.append(74.1)
temps.append(75.7)
#Print the temperatures
print "Daily temperatures for the last ",NUM_TEMPS,"days:\n"
for ctr in range(0,NUM_TEMPS,1):
print '%.2f' %temps[ctr],"\n"
NUM=8
nums=[]
total=0
for ctr in range(0,NUM,1):
print "Please enter the next number...",
nums.append(input())
total+=nums[ctr]
#Prints the sum of eight values
print "The total of the numbers is ",total,"\n"
NUM=12
sales=[]
print "Please enter the twelve monthly sales values\n"
#Fill the array with input values entered by the user
for ctr in range(0,NUM,1):
print "What are sales for month number ",ctr+1,"?\n"
sales.append(input())
#for ctr in range(0,25,1):
# print "\n" #Clears the screen
print "\n\n*** Sales Printing Program ***\n"
print "Prints any sales from the last ",NUM," months\n"
ans='Y'
while ans=='Y':
print "For what month (1-",NUM,") do you want to see a sales value? "
req_month=input()
print "\nMonth ",req_month,"'s sales are",'%.2f' %sales[req_month-1]
print "\nDo you want to see another (Y/N)? "
ans=raw_input().upper()
SIZE=15 #Maximum size of array
ara=[None]*SIZE #Empty Array declaration with maximum size
ara=[5,2,7,8,36,4,2,86,11,43,22,12,45,6,85]
high_val=ara[0] #initialize wit first array element
for ctr in range(1,SIZE,1):
if ara[ctr]>high_val: #Compares with rest of the elements in the array
high_val=ara[ctr] #Stores higher value in high_val
print "The highest number in the list is ",high_val,".\n"
#Maximum size of array
SIZE=15
#Initialize empty array
ara=[None]*SIZE
#Fill array with random numbers from 0 to 99
import random
for ctr in range(0,SIZE,1):
ara[ctr]=random.randint(0,99) %100
print "Here are the ",SIZE,"random numbers:\n"
for ctr in range(0,SIZE,1):
print ara[ctr],"\n" #Prints the array
print "\n\n"
#Initialize first element to both high_val and low_val
high_val=ara[0]
low_val=ara[0]
for ctr in range(1,SIZE,1):
if ara[ctr]>high_val: #Compares with rest of the elements in the array
high_val=ara[ctr] #Stores higher valure in high_val
if ara[ctr]<low_val:
low_val=ara[ctr] #Stores lower valure in low_val
print "The highest number in the list is ",high_val,"\n"
print "The lowest number in the list is ",low_val,"\n"
MAX=100
def fill_parts(parts): #Function assigns first five parts to array for testing
parts[0]=12345
parts[1]=24724
parts[2]=54154
parts[3]=73496
parts[4]=83925
return parts
parts=[None]*MAX
num_parts=5 #Beginning inventory count
fill_parts(parts) #Fills the first five elements
search_part=0
while search_part != -9999:
print "\n\nPlease type a part number...(-9999 ends program)",
search_part=input()
if search_part==-9999:
break #Exits the loop if user wants
for ctr in range(0,num_parts,1): #Scans array to see whether part is in inventory
if search_part==parts[ctr]:
print "\nPart ",search_part,"is already in inventory"
break
else:
if ctr==num_parts-1:
parts[num_parts]=search_part #If not then it is added to end of the array
num_parts+=1
print search_part,"was added to inventory\n"
break
MAX=10
#Fill array with random numbers from 0 to 99
def fill_array(ara):
import random
for ctr in range(0,MAX,1):
ara[ctr]=random.randint(0,99) %100
#Prints the array ara[]
def print_array(ara):
for ctr in range(0,MAX,1):
print ara[ctr],"\n"
#Sorts the array
def sort_array(ara):
for ctr1 in range(0,MAX-1,1):
for ctr2 in range(ctr1+1,MAX,1):
if ara[ctr1]>ara[ctr2]: #Swap if this part is not in order
temp=ara[ctr1] #Temporary variable to swap
ara[ctr1]=ara[ctr2]
ara[ctr2]=temp
ara=[None]*MAX
fill_array(ara)
print "Here are the unsorted numbers:\n"
print_array(ara) #Prints the unsorted array
sort_array(ara) #Sorts the array in ascending order
print "\n\nHere are the sorted numbers:\n"
print_array(ara) #Prints the sorted array
MAX=10
#Fill array with random numbers from 0 to 99
def fill_array(ara):
import random
for ctr in range(0,MAX,1):
ara[ctr]=random.randint(0,99) %100
#Prints the array ara[]
def print_array(ara):
for ctr in range(0,MAX,1):
print ara[ctr],"\n"
#Sorts the array
def sort_array(ara):
for ctr1 in range(0,MAX-1,1):
for ctr2 in range(ctr1+1,MAX,1):
if ara[ctr1]<ara[ctr2]: #Swap if this part is not in order
temp=ara[ctr1] #Temporary variable to swap
ara[ctr1]=ara[ctr2]
ara[ctr2]=temp
ara=[None]*MAX
fill_array(ara)
print "Here are the unsorted numbers:\n"
print_array(ara) #Prints the unsorted array
sort_array(ara) #Sorts the array in descending order
print "\n\nHere are the sorted numbers:\n"
print_array(ara) #Prints the newly sorted array
#Two dimensional array declaration
disks= [[[] for ni in range(4)] for mi in range(2)]
#Assign values to the 2Darray
disks[0][0]=2.39
disks[0][1]=2.75
disks[0][2]=3.29
disks[0][3]=3.59
disks[1][0]=1.75
disks[1][1]=2.19
disks[1][2]=2.69
disks[1][3]=2.95
#Print the values in the array
for row in range(0,2,1):
for col in range(0,4,1):
print "$",'%.2f'%disks[row][col],"\n",
#Two dimensional array declaration
disks= [[[] for ni in range(4)] for mi in range(2)]
#Assign values to the 2Darray
disks[0][0]=2.39
disks[0][1]=2.75
disks[0][2]=3.29
disks[0][3]=3.59
disks[1][0]=1.75
disks[1][1]=2.19
disks[1][2]=2.69
disks[1][3]=2.95
#Print the values in the array
for row in range(0,2,1):
for col in range(0,4,1):
print "$",'%.2f'%disks[row][col],"\t",
print "\n"
#Two dimensional array declaration
disks= [[[] for ni in range(4)] for mi in range(2)]
#Assign values to the 2Darray
disks[0][0]=2.39
disks[0][1]=2.75
disks[0][2]=3.29
disks[0][3]=3.59
disks[1][0]=1.75
disks[1][1]=2.19
disks[1][2]=2.69
disks[1][3]=2.95
#Print the column titles.
print "\tSingle-sided\tDouble-sided\tSingle-sided\tDouble-sided"
print "\tDouble-density\tDouble-density\tHigh-density\tHigh-density"
#Print the prices
for row in range(0,2,1):
if row==0:
print "3-1/2\"\t",
else:
print "5-1/2\"\t",
for col in range(0,4,1):
print "$",'%.2f'%disks[row][col],"\t\t",
print "\n"
#Function definition
def swap_them(num1,num2):
num1,num2=num2,num1
return num1,num2
#Variable declaration
i=10
j=20
print "\nBefore swap, i is ",i,"and j is ",j,"\n"
i,j=swap_them(i,j) # Function call
print "\nAfter swap, i is ",i,"and j is ",j,"\n"
#Variable Declaration
c="Bettye Lou Horn"
#Result
print "My sister's name is ",c,"\n"
#Variable Declaration
c="Bettye Lou Horn"
print "My sister's maiden was ",c,"\n"
#Assigns new string to c
c="Bettye Lou Henderson"
#Result
print "My sister's married name is ",c,"\n"
#Variable Declaration
c="Bettye Lou Horn"
print "My sister's maiden was ",c,"\n"
c+=str(11) #makes c points to the last name
c="Henderson" #Assigns new string to c
#Result
print "My sister's married name is ",c,"\n"
#Array declaration
name=["George","Michelle","Joe","Marcus","Stephanie"]
#Result
for ctr in range(0,5,1):
print "String #",(ctr+1),"is",name[ctr],"\n"