0
0
Goprogramming~10 mins

Nested conditional statements in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

Go
package main

import "fmt"

func main() {
    num := 5
    if num [1] 0 {
        fmt.Println("Positive number")
    }
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks only if the number is zero.
2fill in blank
medium

Complete the code to check if a number is positive and even.

Go
package main

import "fmt"

func main() {
    num := 4
    if num > 0 {
        if num [1] 2 == 0 {
            fmt.Println("Positive even number")
        }
    }
}
Drag options to blanks, or click blank then click option'
A%
B+
C*
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '/' divides the number but does not check for evenness.
Using '*' or '+' are arithmetic operations, not for checking divisibility.
3fill in blank
hard

Fix the error in the nested if statement to check if a number is negative and odd.

Go
package main

import "fmt"

func main() {
    num := -3
    if num [1] 0 {
        if num%2 != 0 {
            fmt.Println("Negative odd number")
        }
    }
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D>=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '>' checks for positive numbers instead of negative.
Using '==' checks if the number is zero.
4fill in blank
hard

Fill both blanks to check if a number is zero or positive and even.

Go
package main

import "fmt"

func main() {
    num := 0
    if num [1] 0 {
        if num [2] 2 == 0 {
            fmt.Println("Zero or positive even number")
        }
    }
}
Drag options to blanks, or click blank then click option'
A>=
B<
C%
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '>' excludes zero from the check.
Using '/' instead of '%' for checking evenness.
5fill in blank
hard

Fill all three blanks to check if a number is negative, odd, and less than -10.

Go
package main

import "fmt"

func main() {
    num := -15
    if num [1] 0 {
        if num%2 [2] 0 {
            if num [3] -10 {
                fmt.Println("Negative odd number less than -10")
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
A<
B!=
C<=
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '==' instead of '!=' for odd check.
Using '>' instead of '<=' for the last condition.