Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Utmaning: Arbeta med Jämförelseoperatorer | Villkorssatser i Python
Introduktion till Python

book
Utmaning: Arbeta med Jämförelseoperatorer

Uppgift

Swipe to start coding

Du har fått variablerna first, second och third. Använd jämförelseoperatorer för att kontrollera följande:

  • Har first samma värde som third? Spara resultatet i variabeln first_comparison.
  • Är produkten av first * second mindre än produkten av third * first? Spara resultatet i variabeln second_comparison.

Lösning

first = -5
second = 10
third = -50

# Write your code here
first_comparison = first == third
second_comparison = first * second < third * first

# Testing
print("The result of the first comparison:", first_comparison)
print("The result of the second comparison:", second_comparison)
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2
first = -5
second = 10
third = -50

# Write your code here
first_comparison = ___
second_comparison = ___

# Testing
print("The result of the first comparison:", first_comparison)
print("The result of the second comparison:", second_comparison)
toggle bottom row
some-alt