Jump to content

Again, with the homework that's been turned in and graded. Basically, the program takes input form the user and "determines their best job opportunity". As opposed to writing a miles long decision tree, I broke each decision into a single function and wrote that, then called the functions when necessary. Is this smart, or dumb? What would you improve, besides input filtering (we were explicitly forbade from doing any input filtering): why and how?

 

# This function is just me being lazy. It prints the result statement with the job being a variable.
def ToScreen(jobTitle):
    print("You could be a ", jobTitle)

# Entertainment determines what type of entertainment the user would like to be in.
def Entertainment():
    userChoice = input("Are you:\n\nA) Soggy\nB) Very Dry\n\nPlease input your choice here: ")
    if userChoice == "A":
        ToScreen("Jello Sculptor")

    else:
        ToScreen("Stand Up Comedian")

# RBE determines if the user would like to be in Research, Business, or Entertainment
def RBE():
    userChoice = input("Please select a job field below\n\nA) Research\nB) Business\nC) Entertainment\n\nPlease input your choice here: ")

    if userChoice == "A":
        ToScreen("Virologist")

    elif userChoice == "B":
        ToScreen("Chief Info Officer")

    else:
        Entertainment()

# Heights determines if the user is afraid of heights or not.
def Heights():
    userChoice = input("Are you afraid of heights?\n\nA) Yes\nB) No\n\nPlease input your choice here: ")

    if userChoice == "A":
        ToScreen("Dog Walker")

    else:
        ToScreen("Crane Operator")

# Outdoor determines if the user would like a job in the city or the country.
def Outdoor():
    userChoice = input("Do you prefer:\n\nA) City\nB) Country\n\nPlease input your choice here: ")

    if userChoice == "A":
        Heights()

    else:
        ToScreen("Ostrich Farmer")

# Main determines whether the user wants an indoor or outdoor job.
def Main():
    userChoice = input("Which type of job would you like?\n\nA) Indoor\nB) Outdoor\n\nPlease input your choice here: ")

    if userChoice == "A":
        RBE()

    else:
        Outdoor()

# Call the Main function to start the program.
Main()

 

ENCRYPTION IS NOT A CRIME

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/
Share on other sites

Link to post
Share on other sites

3 minutes ago, James7176 said:

ToScreen? Never used that before.

It's a function that I defined. It's at the top. It exists just because the output would always be "you could be a <insert job here>". So I just wrote that so I wouldn't have to write the same thing over and over and wish I was dead. Gotta make these overly simple introductory lessons difficult somehow. Would you have just done it all in one go?

ENCRYPTION IS NOT A CRIME

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/#findComment-8549431
Share on other sites

Link to post
Share on other sites

Just now, straight_stewie said:

It's a function that I defined. It's at the top. It exists just because the output would always be "you could be a <insert job here>". So I just wrote that so I wouldn't have to write the same thing over and over and wish I was dead. Gotta make these overly simple introductory lessons difficult somehow. Would you have just done it all in one decision tree?

So you did, I only read the second half. o.O

CPU: R5 3600 @ 4.4 GHz

RAM: 16GB DDR4 @ 3200 MHz

GPU: RTX 2080 Super 

 

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/#findComment-8549439
Share on other sites

Link to post
Share on other sites

that's not lazy that's DRY (don't repeat yourself) also breaking code down into functions is fine amd how I would have likely done it because trying to do this in nested ifs would be stupid.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/#findComment-8549728
Share on other sites

Link to post
Share on other sites

7 hours ago, vorticalbox said:

that's not lazy that's DRY

Speaking of which, I'm thinking of adding some functionality to that function. When the job is "Ostrich Farmer" the output of the "ToScreen()" function is "You could be a Ostrich Farmer" which just looks funny. Since strings are iterables in python, it shouldn't be too hard to determine if the first letter of the first word is a vowel or not and then switch between "a" and "an" based on that determination. 

I think I'm definitely going to do that. It will give me a good first introduction to RegEx

ENCRYPTION IS NOT A CRIME

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/#findComment-8551737
Share on other sites

Link to post
Share on other sites

3 minutes ago, straight_stewie said:

Speaking of which, I'm thinking of adding some functionality to that function. When the job is "Ostrich Farmer" the output of the "ToScreen()" function is "You could be a Ostrich Farmer" which just looks funny. Since strings are iterables in python, it shouldn't be too hard to determine if the first letter of the first word is a vowel or not and then switch between "a" and "an" based on that determination. 

I think I'm definitely going to do that. It will give me a good first introduction to RegEx

A vs An is a lot more complicated than just looking at the first letter of the next word. It would be much easier and more correct to just print something like "You could be a(n) Ostrich Farmer"

1474412270.2748842

Link to comment
https://linustechtips.com/topic/661292-python-stupid-or-correct/#findComment-8551745
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×