Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilrg18/0ffa2d5815277ba80774 to your computer and use it in GitHub Desktop.
Save gilrg18/0ffa2d5815277ba80774 to your computer and use it in GitHub Desktop.
Quiz11
#Gilberto Rogel García Quiz11 Question1
import statistics
def readNumbersFromFile():
fint=[]
f=open('random_numbers.txt','r') #'r' = read 'w'= readwrite
lines=0
total=0
for line in f:
total+= int(line)
lines +=1
fint.append(int(line))
std=statistics.stdev(fint)
avg=total/lines
print("The total is:",total)
print("Number of lines:",lines)
print("The average is:",avg)
print("The standard deviation is:", std)
readNumbersFromFile()
#Gilberto Rogel García
def check_banana(file):
txt=open("banana.txt","r")
ban=0
for b in txt:
low=b.lower()
sh=low.find("banana")
while sh !=-1:
ban= ban + 1
sh=low.find("banana",(sh+1))
return ban
close("banana.txt")
total=check_banana("banana.txt")
print ("The number of times that the word banana was found is:",total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment