Question

In: Computer Science

Python #Use an input statement to ask the user for his/her age (no prompt) and assign...

Python

#Use an input statement to ask the user for his/her age (no prompt) and assign the user entry to a variable
#Convert the user input to an integer and assign to a variable
#Write if-elif-else statements with the following conditions and actions
#Important: For each Action below, use the same variable name for the rating in all the if, elif, and else statements
#Condition: user input less than or equal to 9 Action: assign the letter G as a string to a variable
#Condition: user input less than or equal to 12 Action: assign the letters PG as a string to a variable
#Condition: user input less than or equal to 16 Action: assign the phrase PG-13 as a string to a variable
#Condition: all other conditions Action: assign the letter R as a string to a variable
#Use the + concatenator to display the following on screen
#(replace [rating] with the value of the variable where you stored the allowed rating):
#You are ok to view [rating] movies!
#Regardless of condition, display the following as the last line: Thanks for watching movies!

Solutions

Expert Solution

In this Python program,

  • We accept user input  and assign the user entry to a variable
  • Then we convert into an int and then again  assign to a variable
  • We are implementing the if-elif-else statements with the following provided conditions and actions using the int variable
  • Then we are printing the ratings and finally followed by a terminating message.

(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)

Code:

#Use an input statement to ask the user for his/her age and assign the user entry to a variable
userInput=input()

#Convert the user input to an integer and assign to a variable
userAge=int(userInput)


#Writing an if-elif-else statements with the following conditions and actions

#Condition: user input less than or equal to 9 Action: assign "G" to a variable
if userAge<=9:
rating="G"
#Condition: user input less than or equal to 12 Action: assign "PG" to a variable
elif userAge<=12:
rating="PG"
#Condition: user input less than or equal to 16 Action: assign "PG-13" to a variable
elif userAge<=16:
rating="PG-13"
#Condition: all other conditions Action: assign "R" to a variable
else:
rating="R"

#Use the + concatenator to display the following on screen
#(replace [rating] with the value of the variable where you stored the allowed rating):
print("You are ok to view "+rating+" movies!")

#Regardless of condition, display the last line
print("Thanks for watching movies!")

Note: Please check the screenshot for Indentation, This compiler will usually remove all the Indentation which is provided.

Please check the compiled program and its output for your reference:

Output:

Sample case-1:

Sample case-2:

Sample case-3:

Sample case-4:


Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...


Related Solutions

Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
python: ask the user to input a sequence of positive numbers. the end of the sequence...
python: ask the user to input a sequence of positive numbers. the end of the sequence is determined when the user enters a negative number. print out the maximum number from the sequence. output: keep entering positive numbers. to quit, input a negative number. enter a number: 67 enter a number: 5 enter a number: 8 enter a number: -3 largest number entered: 67 (note: i do not want to ask the user how many numbers they will input)
Write a Python code that will ask a user to input a year and return "Leap...
Write a Python code that will ask a user to input a year and return "Leap Year" if the year is a leap year, or "No Leap Year" if it is not a leap year. The program then asks for another year and performs the same task in the form of a loop, until the user inputs the then integer "-1." At that point, the program will exit the loop.
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Python 2.7 Question: If-Else Statement Is there a way for me to ask the user a...
Python 2.7 Question: If-Else Statement Is there a way for me to ask the user a series of questions with an if-else statement? For example, if a statement is true ask these questions, if false ask these questions. This is what I have so far: if user_input == "yes ": ques.check_string("Enter Name: ") ques.check_string("Enter email: ") elif user_input != "yes": ques.check_string("Enter Name:  ") ques.check_string("Enter phone number: ")   
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write a code in Python jupytoer note book: Ask the user to input a year. Check...
Write a code in Python jupytoer note book: Ask the user to input a year. Check if this is a leap year or not. Ask the user to input a number. Check if this number is even or odd. HbA1c of 6.5% or higher indicates diabetes. 5.7 to 6.4 indicates pre-diabetes. HbA1c less than 5.7 is considered normal. Ask the user for their HbA1c level and display if their they are in the normal range, pre-diabetic, or diabetic. Ask the...
Create a python program that will ask the user for his job title and print out...
Create a python program that will ask the user for his job title and print out the first letter, the last letter and the total number of letters in his job
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT