حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

محاسبه هزینه آب ساختمان

تمرین آسان 1569 visibility link download flag

برنامه‌ای بنویسید که میزان مصرف آب کل ساختمان و تعداد ساکنین هر واحد را دریافت کند. سپس با تقسیم مصرف کل به تعداد کل ساکنین، سهم هر واحد را محاسبه کرده و میزان مصرف را به همراه هزینه نهایی نمایش دهد.


هزینه هر لیتر آب را ۵۰۰ تومان در نظر بگیرید.

این تمرین یه پروژه ست! یعنی پتانسیل اینو داره که خیلی بیشتر روش کار بشه بنابراین ایده اصلی رو از اینجا بردار و خودت بیشتر روش کار کن تا به یه تمرین بزرگتر تبدیل یشه
👨‍💻 5 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 20

water = float(input())
units = int(input())

people = 0

for i in range(units):
    people += int(input())

share = water / people
cost = share * 500

print("مصرف هر واحد:", share)
print("هزینه نهایی:", cost)
include include include

using namespace std;

struct Unit {
int residents;
double water;
double cost;
};

void getConsumption(int &Consumption) {
cout << "Please enter the full water consumption of the building: ";
cin >> Consumption;
}

void getUnits(int &Unitss) {
cout << "Please enter the units number: ";
cin >> Unitss;
}

void getUnitsresidents(vector &units, int const &Unitss) {
units.resize(Unitss); // allocate size

for (int i = 0; i < Unitss; i++) {
    cout << "Please enter residents for unit number " << i + 1 << ": ";
    cin >> units[i].residents;
}

}

void calculateShare(vector &units, int const &Unitss, int const &Consumption) {
cout << fixed << setprecision(2);

for (int i = 0; i < Unitss; i++) {
    units[i].water = (double)Consumption / units[i].residents;
    units[i].cost = units[i].water * 500;
}

}

void Report(const vector &units, int const &Unitss) {
for (int i = 0; i < Unitss; i++) {
cout << "Unit #" << i + 1
<< " | share: " << units[i].water
<< " | cost: " << units[i].cost << " Toman" << endl;
}
}

int main() {
int Consumption, Unitss;
vector units;

getConsumption(Consumption);
getUnits(Unitss);
getUnitsresidents(units, Unitss);
calculateShare(units, Unitss, Consumption);
Report(units, Unitss);

return 0;

}

running=True
TEDAD_HARVAHED=[]
def sum_list(lst):
    total = 0
    for num in lst:
        total += float(num) 
    return total

def dade(a,b,/):
    c= int(a)/int(b)
    print(f"the total cost is {int(a)*500} IRT")
    print(f"each house must pay {int(c)*500} IRT")
    return ' '

while running:
    try:
        MASRAF_KOL:int=input(f"Enter the max use:")
        break
    except ValueError:
        print(f"Enter the number")

while running:
    try:
        TEDAD_VAHED=int(input(f"Enter the number of the houses:"))
        break
    except ValueError:
        print(f"Enter the number")

for i in range(1,TEDAD_VAHED+1):
    while running:
        try:
            s:int=input(f"Enter the number of people in VAHED {i}:")
            TEDAD_HARVAHED.append(s)
            break
        except ValueError:
            print(f"Enter the number")

kol=sum_list(TEDAD_HARVAHED)
dade(MASRAF_KOL,kol)

#include<bits/stdc++.h>
using namespace std;

int a[1000];

int main (){
    int nafar, vahed;
    double hazine, nafari;
    cin >> hazine >> vahed;
    for(int i = 0; i < vahed; i++){
        cin >> a[i];
        nafar += a[i];
    }
    nafari = hazine / nafar;
    for(int i = 0; i < vahed; i++){
        cout << i + 1 << ':' << (nafari * a[i])* 500 << endl;
    }
}
def water_consumption(total_water, residents):
    total_residents = sum(residents)
    cost_per_liter = 500
    share_per_unit = total_water / total_residents
    total_cost = total_water * cost_per_liter

    for i in range(len(residents)):
        unit_cost = share_per_unit * cost_per_liter * residents[i]
        print(f"واحد {i+1}: مصرف آب = {share_per_unit:.2f} لیتر، هزینه = {unit_cost:.2f} تومان")

    print(f"هزینه کل: {total_cost:.2f} تومان")

# مثال استفاده
total_water = float(input("میزان مصرف آب کل ساختمان (لیتر): "))
num_units = int(input("تعداد واحدها: "))
residents = []

for i in range(num_units):
    resident_count = int(input(f"تعداد ساکنین واحد {i+1}: "))
    residents.append(resident_count)

water_consumption(total_water, residents)
پاسخ هوش مصنوعی Ai Python
water=input ("Enter how much water used: ")
people=input("How many people live in the house: ")
water=int (water)
people=int (people)
a=water*500
print("Every persen should pay:{} ".format (a/people))

u=0 
h=[]
s=float(input("Please provide the total amount of water used by the building in liters?\n"))
k=int(input("Please provide the number of units in the building?\n"))
for i in range(k):
    b=int(input(f"Please indicate the number of residents in the {i+1} unit of the building?\n"))
    h.append(b)
for j,l in enumerate(h):
    print(f"The {j+1} unit's water share is {l*(s/(sum(h)))} and its cost is {l*(s/(sum(h)))*500000}")

water_price = 5000
water_usage = int(input("How many litters this apartment uses : "))
apartment = int((input(" HOW MANY PEOPLE ARE IN THIS APARTMENT : ")))

water_usage_per_person = water_usage / apartment

print(f"{water_usage_per_person} * {apartment} = {water_usage_per_person * apartment} price of water for every person ")

cost_per_liter_of_water = 500

water_consumption = int(input("Enter water consumption: "))
number_of_residents = int(input("Enter number of residents: "))
each_unit_apartment = water_consumption / number_of_residents
print(f"share of each unit: {each_unit_apartment}")

final_cost = each_unit_apartment * cost_per_liter_of_water
print(f"Finall Cost: {final_cost}")

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن