+ 4
halloween candy solution!
anyone have a better solution? Mine works but it feels janky: houses = int(input()) #your code goes here dollarchance = 2 / houses percent = (dollarchance * 100) + .5 print(round(percent))
11 Respostas
+ 5
Here you go. In Java.
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int houses = input.nextInt();
//your code goes here
double percent =200;
//your code goes here
if(houses>=3){
percent /=houses;
System.out.println((int)Math.ceil(percent));
}
}
}
+ 4
Brenner Pieszak has added 0.5 as he is using Math.round
The 0.5 will tip any random fraction to over 0.5, but under 1.5 which will always be rounded to 1
When we compare with Ore, the formula used here is Math.ceil which in itself does the work of adding 0.5.
Hope what I said is comprehensible đ
+ 4
0.5 is used because if the round function is used on its own, if the number after the decimal is less than 5 (such as 30.4) then it will return 30, whereas we want it to return 31, using "+0.5" turns "30.4 into "30.9" which can then be used by the round function to make 31. Hope that helps :)
+ 2
print(math.ceil((2 / houses ) * 100))
+ 2
houses = int(input())
#your code goes here
print (round(2 / houses * 100 + 0.5) )
+ 1
sorry, can someone explain to me why add `+0.5` to percent?
0
this is for the code coach halloween candy btw!
0
Awesome, thanks!
0
import math
houses = int(input())
print(math.ceil((100/houses) * 2))
0
Cpp?? Anyone???
0
This is for you C# bros out there.đ
using System;
double houses;
double percent;
houses = Convert.ToInt32(Console.ReadLine());
percent = Convert.ToInt32((2 / houses) * 100 + 0.5);
Console.WriteLine(percent);