logo

Crowdly

A booking should be accepted only when:   the number of people is be...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

A booking should be accepted only when: 

  • the number of people is between 2 and 6 inclusive, and
  • payment has been made. 

A student writes: 

people = 9 

paid = False 

 

if people >= 2 or people <= 6 and paid: 

    print("Accepted") 

else: 

    print("Rejected") 

In Python, and is evaluated before or, so the condition is equivalent to: 

people >= 2 or (people <= 6 and paid) 

  1. State the exact output for the values shown and explain why the condition produces it. [2 marks]
  2. Write a corrected condition and explain how it enforces the booking requirements. [2 marks] 

More questions like this

Want instant access to all verified answers on moodle1.maths.ed.ac.uk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!