Question

In: Computer Science

We will extend project 2 by wrapping our input and output in a while loop. Repeatedly...

We will extend project 2 by wrapping our input and output in a while loop. Repeatedly do the following:

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 is $10. If their age is 65 or greater, the ticket price is $8.

When all the user input has been gathered, print out a meaningful label such as 'Name: ' followed by the entire user name on one line. On the next line, print out a meaningful label such as 'Age: ' followed by the user's age. On the next line, print out a meaningful label such as 'Ticket Price: ' followed by the ticket price your program calculated. Your output should look something like this:

Name: Mickey M Mouse

Age: 19

Ticket Price: $10

Now prompt the user asking if they would like to enter another ticket buyer's name. If they answer 'y' for yes, perform the loop again getting the input from the user, calculate the ticket price, and output the information. If the user answers anything other than 'y' the loop should exit.

in Python please

Solutions

Expert Solution

while True:

    # Prompt the user for their name, get and store the user input.

    name = input("Enter your name: ")

    # Prompt the user for their age, get and store the user input.

    age = int(input("Enter your age: "))

    # If their age is 12 or under, the ticket price is $5.

    price = 5

    # If their age is between 13 and 64, inclusive, the ticket price is $10.

    if age > 13 and age <= 64:

        price = 10

    # If their age is 65 or greater, the ticket price is $8.

    else:

        price = 8

    # print out a meaningful label such as 'Name: ' followed by the entire user name on one line.

    print("Name:", name)

    # print out a meaningful label such as 'Age: ' followed by the user's age.

    print("Age:", age)

    # print out a meaningful label such as 'Ticket Price: ' followed by the ticket price your program calculated.

    print("Ticket Price:", price)

    # Now prompt the user asking if they would like to enter another ticket buyer's name.

    choice = input(

        "Enter 'y' if you want to enter another ticket buyer's name: ")

    # If they answer 'y' for yes, perform the loop again getting the input from the user,

    #  calculate the ticket price, and output the information.

    # If the user answers anything other than 'y' the loop should exit.

    if choice != 'y':

        break

.

Screenshot:

Output:

.


Related Solutions

Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1 is entered, stop prompting for numbers and display the maximum number entered by the user. I am struggling to have my program print the math function. Here is what I have so far: import java.util.*; public class MaxSentinel { public static void main(String[] args) {    Scanner input = new Scanner(System.in); System.out.println("Please enter a value. Press -1 to stop prompt."); int number = 0;...
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads...
Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads in a list of integers as SCOREs, one per line, until a sentinel value of -1. After user type in -1, the application should print out how many SCOREs are typed in, what is the max SCORE, the 2nd max SCORE, and the min SCORE, the average SCORE after removing the max and min SCORE. When SCORE >= 90, the school will give this...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the integers SORTED USING RADIX SORT. You may assume all your input consists of integers <=9999. Your main program will input the integers and put them into a QUEUE. It will then pass this queue to a method called radixSort which will sort the numbers in the queue, passing the sorted queue back to main. The main program will then call another method to print...
Take a coin that lands “heads” with probability 1/2 and flip it repeatedly while keeping trackof...
Take a coin that lands “heads” with probability 1/2 and flip it repeatedly while keeping trackof the pattern of “heads” and “tails” that you see. Use 1 to denote a “head” and 0 to denotea “tail”. We are interested in computing the frequency of the pattern{1, 1, 0}, i.e., of seeingtwo consecutive “heads” followed by a “tail”. To do this we construct a Markov chain whosestate space consists of all the possible 3-flip patterns:1){1, 1, 1}2){1, 1, 0}3){1, 0, 1}4){0,...
Where is the infinite loop in the code? Input for the code 1 2.5 2 40200000...
Where is the infinite loop in the code? Input for the code 1 2.5 2 40200000 1 0 2 80400000 2 ffffffff 3 #include <stdio.h> #include <math.h> #include <stdlib.h> int count = 31; void toBinary(int num, int n){ for(int i = 1; i < n; i++){ if((int)(num/pow(2,(n-i))) > 0){ num = num - pow(2,(n-i)); printf("1"); count--; }else{ printf("0"); count--; } } } char checkSign (int sign) { char new_sign; if (sign == 0) { new_sign = '+'; return new_sign; }...
Using Netbeans update the Sales project so the input and the output are done through a...
Using Netbeans update the Sales project so the input and the output are done through a GUI of your choice. The classes design should not be changed, only the code in the test class. public abstract class Account { private int accountId; public Account(int id){ this.accountId=id; } //getters public int getAccountId() { return accountId; } //setters public void setAccountId(int accountId) { } //abstract method to calculate sales public abstract double calculateSales();    //to string method @Override public String toString() {...
Define a java problem with user input, user output, Do While Statement and some mathematical computation....
Define a java problem with user input, user output, Do While Statement and some mathematical computation. Write the pseudocode, code and display output.
In this project students will write a very simply program using Java’s input and output methods....
In this project students will write a very simply program using Java’s input and output methods. The program will prompt the user to enter responses to several questions, displaying the answer each time. The project is designed to give students an opportunity to practice very basic input and output via a simple project. Specification When the Java program starts it should prompt the user for input and print a response (including that input) as follows: Hello. What is your name?...
Consider 2-bit input functions that has either constant output (0 or 1) or balanced output (the...
Consider 2-bit input functions that has either constant output (0 or 1) or balanced output (the number of {0,1} outputs are equal to each other). First a class is selected with1/2 probability and then one of the functions that belong to the chosen class is selected uniform randomly. We would like to guess the class of the function with minimum function evaluations. • What is the average number of guesses before we identify the chosen class using classical bits? •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT