logo

Crowdly

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

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

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] 

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на moodle1.maths.ed.ac.uk?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!