Can Matt Buy a PS5 on His Birthday? - Algorithm and Python Code
To determine if Matt can buy a PS5 on his birthday, we need to calculate his total savings until his birthday and compare it to the cost of the PS5.
First, we need to determine the number of paydays between the current date (U) and his birthday (T). Since each month has 30 days, we can calculate the number of months between U and T using the formula: months = (T - U) / 30.
Next, we need to calculate the total amount of money Matt will receive from his paydays until his birthday. This can be calculated by multiplying the monthly payment (D) by the number of months: savings = D * months.
Finally, we can compare the total savings to the cost of the PS5 (X). If the total savings is greater than or equal to the cost of the PS5, Matt will be able to buy it. Otherwise, he won't be able to afford it.
Here is the code in Python:
D, X, T, U = map(int, input().split())
months = (T - U) // 30
savings = D * months
if savings >= X:
print('true')
elif savings > 0:
print('false')
else:
print('ruined')
原文地址: https://www.cveoy.top/t/topic/o7XR 著作权归作者所有。请勿转载和采集!