87.1k views
1 vote
Can someone convert this code into python? Please I need this code immediately.

int main(void)
{
double a[5],b[5],c=0;
int i;
for(i=0;i<5;i++)//입력
{
scanf("%lf %lf",&a[i],&b[i]);
}
for(i=0;i<5;i++)
{
c+=(b[i]-a[i]-1.0>0) ? ((b[i]-a[i]-1.0>4) ? 4.0 : b[i]-a[i]-1.0): 0;
}
c/=0.5;
c*=5000;
if(c>=150000)
c*=0.95;
else if(c<=50000)
c*=1.05;

printf("%.0f",c);
}

1 Answer

2 votes
Here's the Python equivalent of the given code:

```
def main():
a = [0] * 5
b = [0] * 5
c = 0

for i in range(5): # Input
a[i], b[i] = map(float, input().split())

for i in range(5):
c += ((b[i] - a[i] - 1.0) > 0) * (4.0 if (b[i] - a[i] - 1.0) > 4 else (b[i] - a[i] - 1.0))

c /= 0.5
c *= 5000

if c >= 150000:
c *= 0.95
elif c <= 50000:
c *= 1.05

print("{:.0f}".format(c))

main()
```

Note that the `scanf` function has been replaced with Python's `input` function, and the `printf` function has been replaced with Python's `print` function with formatted output.
User Tingting
by
8.1k points