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)
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.
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 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,...
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...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
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