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

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)
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 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...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and then convert this numerical salary into income class. The following is a guideline to the income class used. The numeric range within parenthesis maps to the preceding class. If the user gave you a number greater than 700,000 or less than 10,000, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use if-else....
Write a Java program that will ask the user for his/her mark (numerical integer mark) and...
Write a Java program that will ask the user for his/her mark (numerical integer mark) and then convert this numerical mark into letter grades. The following is a guideline to the grading scale used. The numeric range within parenthesis maps to the preceding letter grade. If the user gave you a number greater than 100 or less than 0, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT