Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Creating Odd and Even Logic | Conditional Statements in Python
Introduction to Python
course content

Kursinnhold

Introduction to Python

Introduction to Python

1. First Acquaintance with Python
2. Variables and Types in Python
3. Conditional Statements in Python
4. Other Data Types in Python
5. Loops in Python
6. Functions in Python

book
Challenge: Creating Odd and Even Logic

Let's tackle another practice task!

Oppgave

Swipe to start coding

You are given the variables num and result. Using if/else, assign the value to the variable result:

  • If num is odd, assign the string 'odd'.
  • If num is even, assign the string 'even'.

Tip: A number is considered even if, when divided by 2, the remainder (using the % operator) is 0.

Note

In Python, the % operator is used as the modulo operator, which returns the remainder after dividing one number by another. For example, 5 % 2 would return 1, since 2 goes into 5 twice with a remainder of 1.

image

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 8
toggle bottom row

book
Challenge: Creating Odd and Even Logic

Let's tackle another practice task!

Oppgave

Swipe to start coding

You are given the variables num and result. Using if/else, assign the value to the variable result:

  • If num is odd, assign the string 'odd'.
  • If num is even, assign the string 'even'.

Tip: A number is considered even if, when divided by 2, the remainder (using the % operator) is 0.

Note

In Python, the % operator is used as the modulo operator, which returns the remainder after dividing one number by another. For example, 5 % 2 would return 1, since 2 goes into 5 twice with a remainder of 1.

image

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 8
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt