Question

two part question - answered in Python 3 2). Decision Structure: A travel agency is checking...

two part question - answered in Python 3

2). Decision Structure: A travel agency is checking whether its tours are good for customers. It follows the table below to label each tour. (e.g., if a tour has 6 destinations and its price is $600, then it should be labelled as ‘expensive’.)

Number of Destinations Price Label
<5 <300 or >=300 good or expensive
>=5 <500 or >=500 Good or Expensive

Write a program that asks the user to enter the number of destinations in a tour and the price of this tour. The program should display the label for this tour.

3). Repetition Structure: Note: this question is based on question 2), feel free to add the loops directly into the code for question 2) if you want. a). Add a validation loop for question 2). The validation loop should verify that the user’s input for the number of destinations is a positive number, otherwise it should display an error message and ask for another input. b). Add a loop for question 2) so that the program repeats when the user wants to check another tour. (In other words, the program should ask the user whether he/she wants to check another tour after labeling a tour; if the user answers ‘yes’, the program should again prompt the user to enter the number of destinations and price, and display the corresponding label.)

Part 2) and 3) Sample input & output:

(Prompt) Enter the number of destinations: (User enter) 3

(Prompt) Enter the price for the tour: (User enter) 500

(Output) The label of this tour is Expensive (Prompt) Do you want to check another tour? Enter yes if you do: (User enter) yes

(Prompt) Enter the number of destinations: (User enter) -1

(Output) Please enter a positive number of destinations.

(Prompt) Enter the number of destinations: (User enter) 6

(Prompt) Enter the price for the tour: (User enter) 450

(Output) The label of this tour is Good

(Prompt) Do you want to check another tour? Enter yes if you do: (User enter) no

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

input code:

take user input while True: n=int(input(Enter the number of destinations:)) check price is valid or not.. if(n)=0):

output:

Enter the number of destinations: 5 5 Enter the price for the tour:300 Good ... Program finished with exit code 0 Press ENTER

code:

'''take user input'''
while True:
n=int(input("Enter the number of destinations:"))
'''check price is valid or not'''
if(n>=0):
break
else:
print("Please enter a positive number of destinations")
'''take a loop'''
while True:
'''take input'''
price=float(input("Enter the price for the tour:"))
'''check price is valid or not'''
if(price>=0):
break
else:
print("Please enter a positive number of price")
'''check for number of destinations'''
if n<5:
'''check the price'''
if price<300:
'''print this if above is True'''
print("good")
else:
'''else print this'''
print("expensiv")
else:
if price<500:
'''print this if above is True'''
print("Good")
else:
'''else print'''
print("Expensiv")
  

2)

input code:

i=1 while i==1: take user input. while True: n=int(input(Enter the number of destinations:)) check price is valid or n

output:

Enter the number of destinations:3 Enter the price for the tour:500 The label of this tour is Expensive Do you want to check

code:

i=1
while i==1:
'''take user input'''
while True:
n=int(input("Enter the number of destinations:"))
'''check price is valid or not'''
if(n>=0):
break
else:
print("Please enter a positive number of destinations")
'''take a loop'''
while True:
'''take input'''
price=float(input("Enter the price for the tour:"))
'''check price is valid or not'''
if(price>=0):
break
else:
print("Please enter a positive number of price")
'''check for number of destinations'''
if n<5:
'''check the price'''
if price<300:
'''print this if above is True'''
print("The label of this tour is Good")
else:
'''else print this'''
print("The label of this tour is Expensive")
else:
if price<500:
'''print this if above is True'''
print("The label of this tour is Good")
else:
'''else print'''
print("The label of this tour is Expensive")
'''ask for run again or not take input'''
again=input("Do you want to check another tour? Enter yes if you do:")
if again.upper()=='NO' or again.lower()=='no':
i=0
  

Add a comment
Know the answer?
Add Answer to:
two part question - answered in Python 3 2). Decision Structure: A travel agency is checking...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3). Repetition Structure: Note: this question is based on question 2), feel free to add the...

    3). Repetition Structure: Note: this question is based on question 2), feel free to add the loops directly into the code for question 2) if you want. a). Add a validation icop for question 2). The validation loop should verify that the user's input for the number of destinations is a positive number, otherwise it should display an error message and ask for another input. b). Add a loop for question 2) so that the program repeats when the user...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • In Python. Complete the following programs. Begin each program with a comment that includes: • Your...

    In Python. Complete the following programs. Begin each program with a comment that includes: • Your name • The project/program • Brief description of the problem Lab3Pro1 A supervisor in a manufacturing company wishes to display the bonus amount for an employee based on this year's production. Input Output Processing Distribute bonuses as follows: Display the results as follows: Prompt for user input "Enter number of Units produced" Store the amount entered Bonus This year's production bonus will be $nnnnn...

  • Write a Python (3) program to simulate** a buffer overflow (this is a new script, not...

    Write a Python (3) program to simulate** a buffer overflow (this is a new script, not part of the intranet assignment), then implement input validation to prevent it. There are two parts to this assignment: 1) The program should display a welcome message and prompt the user for a username. Create a simulated buffer overflow condition by allowing a user to input more data than the size of the allocated memory (causing the program to crash). 2) Implement input validation...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • PAYTHON PROGRAM WITHOUT ANY FUNCTION AND METHOD A program that will allow a grocery store to...

    PAYTHON PROGRAM WITHOUT ANY FUNCTION AND METHOD A program that will allow a grocery store to keep track of the total number of bottles collected for a seven-day period. The program should allow the user to enter the number of bottles returned for each day of the seven-day period. The program will accumulate the total number of bottles returned for the 7-day period. Then calculate the amount paid out (the total bottles returned times .10 cents). The output (display) of...

  • I am having trouble figuring out what should go in the place of "number" to make...

    I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...

  • Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to...

    Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to Solve (20 Point/Each) Problem l: Triangle Printing Program: Write an application that prints a right triangle with 1 to 8 rows. Prompt the user to enter an odd number in the range of 1 to 8 to specify the number of rows in the diamond. Add a validation loop to ensure the user does not enter an even number or a number outside the...

  • I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For...

    I need the pseudocode and python for the four attached problems: 1. (Chapter 5 - For Loop) Logic Technical College has a current tuition of $10,000 per year. Tuition is scheduled to increase by 5% each year. Using a FOR loop, design a program that calculates and displays the tuition each year for the next ten years, like so: The tuition for year 1 will be: 10500.00 The tuition for year 2 will be: 11025.00 ……….. (You, of course will...

  • Python Coding Help

    How to write a code for this?When the program starts the bowler is prompted for a score for ‘Game 1’Accept the bowling score from the user; valid bowling scores are whole numbers between 0 and 300.Once a valid numeric score is entered then perform range validation to ensure it is within the required entry range. If the bowler enters a value outside of the acceptable range, or for any entries that aren’t whole numbers, the program should display an appropriate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT