
Patrick B. answered 11/13/20
Math and computer tutor/teacher
I do not have a python compiler..
I use the online compiler which does NOT allow me to read files on the disk...
Nevertheless, here are some code blocks to get you started..
print("Hello World")
#---------------------------------
# allegedly opening and reading the file
"""
filename = input("Filename ??? :>")
file_obj = open(filename,"r")
inbuff = file_obj.read(255)
print(inbuff)
file_obj.close()
"""
#---------------------------------
#
#use len(str)==0 to check for blank line
#
# this next block of code populates the NAME and FOOD lists
listInput = ["name Patrick","name Franny","food fruit","food vegetables"]
listName = []
listFood = []
N=len(listInput)
print(N)
for iLoop in range(int(N)):
strInbuff = listInput[iLoop]
tokens = strInbuff.split()
if tokens[0]=="name":
listName.append(tokens[1])
if tokens[0]=="food":
listFood.append(tokens[1])
print(listName)
print(listFood)
"""
# MUST have the same # of FOOD as NAMEs in the file_obj
#Finally, the next code block generates random integers
"""
from random import seed
from random import randint
# seed random number generator
seed(1)
# generate some integers
for _ in range(10):
value = randint(0, 10)
print(value)