-
-
Save TheMuellenator/9fe2f689a3e1d9aec2fd631bd98ec606 to your computer and use it in GitHub Desktop.
func isOdd(n: Int) -> Bool { | |
if n % 2 != 0 { | |
return true | |
} else { | |
return false | |
} | |
// Alternatively: | |
// return n % 2 != 0 | |
} | |
let testNumber = Int(readLine()!)! | |
let numberIsOdd = isOdd(n: testNumber) | |
print(numberIsOdd) |
func isOdd(n: Int) ->Bool{
if (n % 2 == 0){
return false
}
else {
return true
}
}
//Do not change the code below.
let testNumber = Int(readLine()!)!
let numberIsOdd = isOdd(n: testNumber)
print(numberIsOdd)
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}
I did exactly this code but my console was returning error. After 10min trying to understand I just realised that my B on Bool wasn't in capital letter. Damn
Solution:
func isOdd(n: Int) -> Bool {
if n%2 == 1 {
return true
} else {
return false
}
}
ha! another one
func isOdd(n: Int) -> Bool {
if n % 2 == 0 {
return false
} else {
return true
}
}
func isOdd(n: Int) -> Bool {
// Number not divisible by 2
if n % 2 != 0 {
return true
} else {
return false
}
}
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}
isOdd(n: 5)
BelowSolutionWorksWellButStillDontKnowWhatThisSymbol%Indicates
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}
isOdd(n: 5)
isOdd(n: 7)
func isOdd(n: Int) -> Bool{
if n % 2 == 0{
return false
}else{
return true
}
}% operator is my fave!
And how do you call this function
BelowSolutionWorksWellButStillDontKnowWhatThisSymbol%Indicates
func isOdd(n: Int) -> Bool {if n % 2 != 0 { return true } else { return false }
}
isOdd(n: 5)
isOdd(n: 7)
How do you call this function ?
When I type "isOdd(n: 5)" I got "Expressions are not allowed at top level"
func isOdd(n:Int) ->Bool {
if n%2 == 0{
return true
}
else{
return false
}
}
let testno = Int(readLine()!)!
var res = isOdd(n:testno)
print(res)
This is my solution
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}
func isOdd(n: Int) -> Bool { return n % 5 != 0 }
let numberIsOdd = isOdd(n: 53)
print(numberIsOdd)
i used this
f```
unc isOdd (n: Int) -> Bool{
if n % 2 == 0 {
return false
}else{
return true
}
}
there is many way to make it work
THIS ONE WORKED FINE FOR ME:
func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}
func isOdd(n: Int) -> Bool {
if n.isMultiple(of: 2) {
return false
} else {
return true
}
}
func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}
isOdd(n: 5)
func isodd(n: Int) -> Bool{
if (n % 2 == 0)
{
return true
} else
{
return false
}
}
var doorShouldopen = isodd(n: 5 )
print(doorShouldopen)
A one-liner:
func isOdd(n: Int) -> Bool {
return n & 1 == 1
}
func isOdd(n: Int) -> Bool{
if n % 2 != 0 {
return true
}else{
return false
}
}
func isOdd(n: Int) -> Bool{
return n % 2 != 0
}
//Try some different numbers below:
//The code below is not part of the exercise, but you can test your own code with different numbers.
let numberIsOdd = isOdd(n: 52)
print(numberIsOdd)
same here