Jul-28-2019, 12:33 AM
Hi, so this is my first time in this forum. I'm new to python coding, and so far the majority of my coding experience has been in regards to web design/development so python has been a massive departure from everything that I've learned so far...well almost. I see similarities with javascript, but I'm not any good with that either.
To the point of the post!
We're into loops now, and I've only just managed to figure out modules. This assignment has the following requirements:
I'm recycling the code from the previous lab to try and incorporate this new type of coding into it.
To help, here is the coding from my last lab (including pseudocode):
Then after marking yes or now, it displays the last module that shows the outcome of your first choice. BUT, after it shows this, I want to make a loop that will allow you to start the little game over again and try out another answer option without having to rerun the whole program.
Now, what I've started to do is placing my new loop module after this module:
I will mention that our class book is trash on showing code in action (it mainly displays the pseudocode and not the actual functioning code that makes it all work). It talks at you and doesn't really show you (if that helps in explaining things). And asking the instructor isn't helpful since it can take a day or two to hear back from them.
Please, any instruction would be greatly appreciated.
To the point of the post!
We're into loops now, and I've only just managed to figure out modules. This assignment has the following requirements:
- A comment at the top with a brief description of the program, including Input List and Output List.
- Your name given as the author.
- Full pseudocode should be included in the comments.
- It must have at least one input and at least one output.
- It must validate the user input. This means the user is not allowed to just enter any value.
- You must check the value, and ask the user to enter it again, and repeat this loop until the user enters a valid value.
- Your program must use at least two loops in meaningful ways. The loops you use for input validation count for at most one of the two required loops. If you use loops to validate two separate inputs, that does not count as two loops for satisfying this lab requirement.
- It should be organized into separate modules (one module for input, one module for output, and one module for each separate calculation or action that the program is to perform [that is, each module should be "cohesive" and should only do one thing]).
- Use parameters and arguments to pass values into your modules (don't use global variables).
The Python code should run correctly, and the logic should match your pseudocode.
I'm recycling the code from the previous lab to try and incorporate this new type of coding into it.
To help, here is the coding from my last lab (including pseudocode):
__author__ = 'Sean Ropp' # The program is based off of a card game by RoosterTeeth called "A Million Dollars...But." # You choose from options A, B, or C. Any other option will ask that you refresh the program. # Input List: answer # Output List: Answer # Module String Question() # Display "We are going to play a game." # Display "You get a million dollars...but," # Display " A: Every time you spend a dollar, someone magically appears and licks your face." # Display " B: Once a week you you have to deal with a ninja stalking you." # Display " C: Anytime you use a bathroom, or restroom, a band of paparazzi appear and take pictures of you." # Display "" # End Module def question(): print("We are going to play a game.") print("You get a million dollars...but,") print(" A: Every time you spend a dollar, someone magically appears and licks your face.") print(" B: Once a week you you have to deal with a ninja stalking you.") print(" C: Anytime you use a bathroom, or restroom, a band of paparazzi appear and take pictures of you.") print("") # Function String answer_choice(): # Declare String answer # # Display "Enter your Choice: " # Input answer # # If answer == 'A' or answer == 'a': # Display "You have chosen A." # Else If answer == 'B' or answer == 'b': # Display "You have chosen B." # Else If answer == 'C' or answer == 'c': # Display "You have chosen C.") # Else: # Display "Refresh and try again." # Return answer # End Function def answer_choice(): answer = input("Enter your Choice: ") if answer == 'A' or answer == 'a': print("You have chosen A.") elif answer == 'B' or answer == 'b': print("You have chosen B.") elif answer == 'C' or answer == 'c': print("You have chosen C.") else: print("Refresh and try again.") return answer # Function String gotten_into(answer) # Display "" # If answer == 'A' or answer == 'a': # Display "This person appears anywhere." # Display """You're standing in a grocery store and buying a soda and some chips.""" # Display "This guy just appears and licks your face for every dollar you just spent." # Display "Just bought a house? Guess who congratulates you for every dollar spent?" # Else If answer == 'B' or answer == 'b': # Display "The ninja appears at some time, once per week, for the next 24hrs." # Display "They never attack you, but they are always there watching you, making threatening gestures." # Display "And they will set traps, use poisons, and just stealthfully make your life difficult for one day." # Display "Their tricks are never harmful, and you can get out of them, or recover from them in a minute." # Else If answer == 'C' or answer == 'c': # Display "They appear and crowd into the bathroom, pushing anyone else around all to catch a picture" # Display "of you doing your business." # Display """They also call out really personal questions like, "are you getting enough fiber,""" # Display """is it the hershey squirts," and other such questions.""" # Display "You then have to push your way through them to get out, but once your out of the" # Display "bathroom they vanish. If you check the tabloids at all, your in them the next day." # Else: # Display "Seriously, make a choice of A, B, or C. No other choice will work." # Return answer def gotten_into(answer): print("") if answer == 'A' or answer == 'a': print("This person appears anywhere.") print("""You're standing in a grocery store and buying a soda and some chips.""") print("This guy just appears and licks your face for every dollar you just spent.") print("Just bought a house? Guess who congratulates you for every dollar spent?") elif answer == 'B' or answer == 'b': print("The ninja appears at some time, once per week, for the next 24hrs.") print("They never attack you, but they are always there watching you, making threatening gestures.") print("And they will set traps, use poisons, and just stealthfully make your life difficult for one day.") print("Their tricks are never harmful, and you can get out of them, or recover from them in a minute.") elif answer == 'C' or answer == 'c': print("They appear and crowd into the bathroom, pushing anyone else around all to catch a picture") print("of you doing your business.") print("""They also call out really personal questions like, "are you getting enough fiber,""") print("""is it the hershey squirts," and other such questions.""") print("You then have to push your way through them to get out, but once your out of the") print("bathroom they vanish. If you check the tabloids at all, your in them the next day.") else: print("Seriously, make a choice of A, B, or C. No other choice will work.") return answer # Module display_all() # Call question() # # Declare answer # # Set answer = answer_choice() # Set answer = gotten_into(answer) # End Module def displaying_all(): question() answer = answer_choice() answer = gotten_into(answer) displaying_all()To meet the requirements for the class, the too loops that I'm thinking of is to stop and check if the answer you want is right. "Are you sure you want this? Yes/No"
Then after marking yes or now, it displays the last module that shows the outcome of your first choice. BUT, after it shows this, I want to make a loop that will allow you to start the little game over again and try out another answer option without having to rerun the whole program.
Now, what I've started to do is placing my new loop module after this module:
def answer_choice():What I've written so far is (I'll do the pseudo later, for some reason it's easier for me to do that last, not first):
def are_you_sure(answer): yes_or_no = input("Yes / No") for answer_choice = "A" or "a" or "B" or "b" or "C" or "c" print("Are you sure you want " answer "?" yes_or_no) if yes_or_no == 'Y' or yes_or_no'y':This is where I'm at and I'm certain that this isn't the way to go with this, but the how to actually go about this in a simple manner is escaping me. Then of course there is the issue of looping back to the start of it all and how that can be done.
I will mention that our class book is trash on showing code in action (it mainly displays the pseudocode and not the actual functioning code that makes it all work). It talks at you and doesn't really show you (if that helps in explaining things). And asking the instructor isn't helpful since it can take a day or two to hear back from them.
Please, any instruction would be greatly appreciated.