MulaiMulai sekarang secara gratis

Checking equality

Before scaling the recipe, you need to check if you have the exact amount of basil required. You'll use an equality check with an if/else statement to determine whether you have exactly the right amount or need to adjust your shopping list.

The integer variables basil_grams and required_basil have been preloaded for you.

Latihan ini adalah bagian dari kursus

Introduction to Python for Developers

Lihat Kursus

Petunjuk latihan

  • Use an equality check to compare basil_grams with required_basil in the if statement condition.
  • Else, print a message when you don't have the exact amount needed.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Check if you have exactly the right amount of basil
if basil_grams ____ required_basil:
    print('Perfect! You have exactly the right amount of basil.')
____:
    print('You need to adjust your basil quantity.')
Edit dan Jalankan Kode