What is the error in my code. When I run it works fine but when I try to submit it, it says I have an issue. any ideas on what it might be.

Homework Help: Questions and Answers: What is the error in my code When I run it works fine but when I try to submit it it says I have an issue. any ideas on what it might be.

Assignment is to Create a function called movie_rated(). Ask the user “What’s the rating?” The user can respond with ‘G’, ‘PG’, ‘PG-13′,’R’,’NC-17′. Then ask the user “How old are you?” to get their age. Finally ask them “Do you have a guardian” which the user will enter “yes” or “no”. Depending on their answers, print “Admitted” or “Not admitted”.

What is the error in my code. When I run it it works fine but when I try to submit it, it says I have an issue. any ideas on what it might be.Assignment is to Create a function called movie_rated(). Ask the user "What's the rating?" The user can respond with 'G', 'PG', 'PG-13','R','NC-17'. Then ask the user "How old are you?" to get their age. Finally ask them "Do you have a guardian" which the user will enter "yes" or "no". Depending on their answers, print "Admitted" or "Not admitted".

G – All ages admitted, no guardian needed
PG – All ages admitted, no guardian needed
PG-13 – All ages admitted, no guardian needed
R – Age under 17 requires accompanying parent or adult guardian. 17 or older allowed to enter.
NC-17 — no one under age 17 admitted

Answer:

From the given photo, the code seems generally fine for executing the desired logic based on the movie rating and age input. However, the logic has a flaw concerning the implementation of the conditions for allowing access based on ratings and age or guardian status.

Lets analysis the potential issues and a suggested fix:

Issues:

  1. Redundancy in Conditions: Your code doesn’t need to ask for a guardian if the rating is ‘G’, ‘PG’, or ‘PG-13’ since all ages are admitted without a guardian for these ratings.
  2. Logic for ‘R’ Rating: For the ‘R’ rating, your code correctly checks if the age is over 17 to admit them, but it doesn’t handle the scenario where a person under 17 has a guardian.
  3. Output Clarity: It’s generally a good practice to also print why a person is not admitted (e.g., age restriction, no guardian) for clearer feedback, though this is more of an enhancement than a bug.

Suggested Code Correction:

Here is a more streamlined version of your code that correctly handles the conditions:

Here is a more streamlined version of your code that correctly handles the conditions:

def movie_rated():
rating = input("What's the rating? (G, PG, PG-13, R, NC-17): ")
age = int(input("What's your age?"))
if rating in ["G", "PG", "PG-13"]:
print("Admitted") # All ages admitted, no need for further checks
elif rating == "R":
if age >= 17:
print("Admitted")
else:
guardian = input("Do you have a guardian with you? (yes or no): ")
if guardian == "yes":
print("Admitted")
else:
print("Not Admitted")
elif rating == "NC-17":
if age >= 17:
print("Admitted")
else:
print("Not Admitted")

movie_rated()

What This Fixes:

  • Removes unnecessary guardian check for ‘G’, ‘PG’, ‘PG-13’ ratings.
  • Adds a guardian check under the ‘R’ rating when the person is under 17.
  • Simplifies the check for ‘NC-17’ rating.

Make sure to test this solution to ensure it meets all the requirements of your assignment prompt and adjust as necessary based on additional constraints or details from the assignment!

Learn More: Homework Help

Q. True or False? Mobile device management (MDM) includes a software application that allows organizations to monitor, control, data wipe, or data delete business data from a personally owned device.

Q. Jeremy forgot where he saved a certain file on her computer Therefore he searches for all files with a .jpg file extension. Which type of file is he searching?

Q. Which three of the following are characteristics of Cisco TrustSec enforcement when deployed with Cisco ISE? Choose three.

Q. In Procrastination: Crash Course Study Skills #6 the speaker says that according to the Pomodoro Technique, if the desire to visit a distracting website arises while studying, the best thing to do is to.

Q. What technology enables computers to understand and interpret human language, making it useful for chatbots and virtual assistants?

Q. Which of the following is true of Link 16 spread spectrum processing?

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Comments