Last active
August 29, 2015 14:20
-
-
Save gilrg18/0ffa2d5815277ba80774 to your computer and use it in GitHub Desktop.
Quiz11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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