Hovercraft challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hovercraft challenge

I have a coding challenge requiring an input, but I am coding in Swift. Unlike Python which has an input() function, I dont have that pleasure. Any help on how I could resolve this?

14th Jul 2021, 6:03 PM
Steven
10 Answers
+ 5
Try this monthly(customers: Int(readLine()!)!)
15th Jul 2021, 1:38 AM
Simba
Simba - avatar
+ 3
Yeah, you're correct. readLine function gives an optional. The exclamation mark is used to forcefully unwrap the optional :)
15th Jul 2021, 1:49 AM
Simba
Simba - avatar
+ 1
Show your attempt
14th Jul 2021, 7:02 PM
Matias
Matias - avatar
+ 1
Steven try the readLine function
14th Jul 2021, 8:19 PM
inxanedev!
inxanedev! - avatar
+ 1
Simba Thank you so much! Would you mind explaining how this works? My understanding is that “!” Unwraps the optional and forces the code to accept the inputted value, is that correct?
15th Jul 2021, 1:42 AM
Steven
+ 1
Dear Steven Take reference from here : https://code.sololearn.com/cSW9Zn6u23iV/?ref=app. Happy CODING!!!
15th Jul 2021, 5:14 AM
Anurag Saikia
+ 1
Anurag Saikia Simba helped me solve it, but thank you
15th Jul 2021, 10:26 AM
Steven
14th Jul 2021, 7:09 PM
Steven
0
inxanedev! I tried using that when I called the function and it failed every test Ex. Monthly(customers: readLine())
14th Jul 2021, 9:00 PM
Steven
0
inxanedev! I have also tried Ex. Monthly(readLine()) And it fails each test
14th Jul 2021, 9:12 PM
Steven