Skip to content

Instantly share code, notes, and snippets.

View som983's full-sized avatar
🎯
Focusing

som983

🎯
Focusing
View GitHub Profile
@som983
som983 / coursera 8.5
Last active August 8, 2020 06:48
Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a c…
fname = input("Enter file name: ")
fh = open(fname)
count = 0
for line in fh:
line=line.rstrip()
if line.startswith('From:'):
continue
if not line.startswith('From'):
continue
words=line.split()
@som983
som983 / coursera 8.4
Last active August 8, 2020 06:48
Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alp…
fname = input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
line=line.rstrip()
words=line.split()
for word in words:
if not word in lst:
lst.append(word)
else:
flname = input("Enter the file name: ")
fhandle = open(flname)
count = 0
total = 0
for i in fhandle:
if not i.startswith("X-DSPAM-Confidence:"):
continue
else:
t = i.find("0")
num = float(i[t+1:].rstrip())
text = "X-DSPAM-Confidence: 0.8475"
startpos= text.find('0')
afterpos= text[startpos:]
endpos= float(afterpos)
print(endpos)
@som983
som983 / Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a tryexcep
Last active October 1, 2020 13:56
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
n=int(num)
@som983
som983 / gist:ede9385ea6ea7be56a6b2b8b4a911d92
Created July 20, 2020 14:24
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The…
def computepay(h,r): #defining the computepay function
if h>40:
p=(1.5*(h-40)*r)+(40*r)
else:
p=40*r
return p
# taking input
hrs =input("Enter Hours:")
h=float(hrs)
rate =input("Enter rate per hour:")
score = input("Enter Score: ")
try:
s=float(score)
except:
print("Error,value out of range") # if type is not float
quit()
if s>=1.0 or s<0.0:
print("Value out of range") #if the value is out of range
elif s>=0.9:
print('A')