Skip to content

Instantly share code, notes, and snippets.

View rehatpsingh's full-sized avatar

Rehatpreet Singh rehatpsingh

  • Waterloo, Ontario
View GitHub Profile
@rehatpsingh
rehatpsingh / 6.5.1.py
Created October 27, 2020 13:08
6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out.
BEST TIME COMPLEXITY METHOD
text = "X-DSPAM-Confidence: 0.8475";
atpos=text.find('0')
print(atpos)
sspos=text.find(' ',atpos)
print(sspos)
host=text[atpos : sspos]
print(float(host))
@rehatpsingh
rehatpsingh / .py
Created October 28, 2020 09:14
7.1 Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file words.txt to produce the output below.
#100% working solution for python backgroud or python 3
fname = input("Enter file name: ")
try:
fh = open(fname)
except:
print('file not found:error')
quit()
text=fh.read()