1. You are missing your input code.
enjoyJob = str(input("Do you enjoy your job?"))
2. String comparisons cannot be done with the or
statement.
if enjoyJob == "n" or "N": # Does not work.
if enjoyJob in ("n", "N"): # Does work.
Python evaluates each side of the or
statement as its own. Your code is the equivalent of doing:
bool1 = bool(enjoyJob == "n") # Depends on enjoyJob.
bool2 = bool("N") # Is always true, since its not an empty string.
if bool1 or bool2:
....
3. name
and job
is not defined, .join()
does not do what you think it does.
print("that's so sad ".join(name))
input("why do you hate " + job + "?")
>>> a = "hey"
>>> a.join("lol")
'lheyoheyl'
4. input(sendLetter)
does not create new variable sendLetter
.
You must assign a variable to the input, and the parameter for the input
function is what is printed to the user. Correct usage is:
user_input = input("Please type in some input: ")
5. You must state what your logic must do if the user doesn't specify y
.
Notice:
if sendLetter() == 'y' or 'Y':
f = open("letter_to_Boss.html", "x")
f.write(letterToBoss)
f.read("letter_to_Boss.html")
f.close()
If the user types n
, the program will crash since the file f
was never initialized.
6. You do not (and can not) read from the opened file.
f = open("letter_to_Boss.html", "x")
f.write(letterToBoss)
f.read("letter_to_Boss.html") # This will return an error.
f.close()
f.read()
will not allow you to read the file (you must open the file with the intention of reading it), and for your purposes, it has no use.
Final Code
With the corrections above, you get a code that looks more like so:
letterToBoss = """<html>"""
name = str(input("What is your name?"))
job = str(input("What is your job?"))
enjoyJob = str(input("Do you enjoy your job?"))
if enjoyJob in ("n", "N"):
print(f"that's so sad {name}")
input(f"why do you hate {job}?")
elif enjoyJob in ("y", "Y"):
print(f"that is awesome {name}")
sendLetter = input("Would you like to send an email to your boss?")
if sendLetter == ("y", "Y"):
f = open("letter_to_Boss.html", "x")
f.write(letterToBoss)
f.close()
elif sendLetter == ("n", "N"):
print("awe shucks")