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

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

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

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


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

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

reply 19

visibility
#من متغیر هارو شانسی زدم شما هرچی دوست داشتین بزنین
p=int(input("ميزان مصرف اب: "))
o=int(input("تعداد هر واحد: "))
i=p/o
u=i*500
print('سهم هر واحد:',i)
print("هزينه ي اب هر واحد:",u)

total_water = float(input("enter masraf kol water sakhetemon : "))

num_vahed = int(input("enter tedad vahed sakhtemon :"))

tedad_sakenin_sakhteman =[]

for i in range(num_vahed):
    sakenin_harvahed = int(input(f"enter sakenin har vahed:{i+1}"))
    tedad_sakenin_sakhteman.append(sakenin_harvahed)

total_sakenin = sum(tedad_sakenin_sakhteman)
water_harnafar = total_water / total_sakenin

for i in range(num_vahed):
    tedad_sakenin = tedad_sakenin_sakhteman[i]
    tedad_water_vahed = tedad_sakenin * water_harnafar
    hazine_nahai_vahed = tedad_water_vahed * 500

print(tedad_water_vahed)
print(hazine_nahai_vahed)

c++

#include <iostream>
#include <cfloat> // برای فهمیدن ظرفیت متغیر ها :
#include <cctype>
#include <vector>
#include <list>
#include <ctime>

using namespace std ;

int main() {

    double water_used = 0 ;
    cout << "Enter water consumed = " ;
    cin >> water_used ;

    double cost = water_used * 500 ;
    cout << "Cost = " << cost << " Toman" << endl;

    int units = 0 ;
    cout << "Enter the number of units in the building = " ;
    cin >> units ;


    list <int> residents = {} ;
    int resident = 0 ;
    for (int i = 1 ; i <= units ; i++) {
        cout << "Unit " << i << " residents = " ;
        cin >> resident ;
        residents.push_back(resident) ;
    }


    int all = 0 ;
    for(int r : residents) {
        all += r ;
    }


    cout << endl << "Residents : " << all << endl << endl;



    double contribution = water_used / all ;

    list <double> unit_shares = {} ;
    double unit_contribution = 0 ;
    for(int r : residents) {
        unit_contribution = contribution * r ;
        unit_shares.push_back(unit_contribution) ;
        unit_contribution = 0 ;
    }



    cout << "Unit's shares = " ;
    for(double x : unit_shares) {
        cout << x << "  " ;
    }
    cout << endl;



    return 0;
}
def calculate_water_share():
    try:
        total_consumption = float(input("میزان مصرف کل آب ساختمان به لیتر را وارد کنید: "))
        num_units = int(input("تعداد واحدهای ساختمان را وارد کنید: "))

        residents = []
        total_residents = 0

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

        if total_residents == 0:
            print("تعداد کل ساکنین نمی‌تواند صفر باشد.")
            return

        cost_per_liter = 500  # تومان

        print("\nنتایج سهم مصرف و هزینه هر واحد:")
        for i, resident_count in enumerate(residents, start=1):
            share = (resident_count / total_residents) * total_consumption
            cost = share * cost_per_liter
            print(f"واحد {i}: مصرف = {share:.2f} لیتر، هزینه = {cost:.0f} تومان")

    except ValueError:
        print("لطفاً مقادیر عددی معتبر وارد کنید.")

if __name__ == "__main__":
    calculate_water_share()
# Constants
COST_PER_LITER = 500  # Cost of each liter of water in Tomans

# Input total water consumption
total_consumption = float(input("Enter the total water consumption (in liters): "))

# Input number of units
num_units = int(input("Enter the number of units: "))

# Initialize total residents
total_residents = 0

# Get the number of residents in each unit
residents_per_unit = []
for i in range(num_units):
    residents = int(input(f"Enter the number of residents in unit {i + 1}: "))
    residents_per_unit.append(residents)
    total_residents += residents

# Calculate water consumption per resident
if total_residents > 0:
    consumption_per_resident = total_consumption / total_residents
else:
    print("Error: Total number of residents cannot be zero.")
    exit()

# Calculate total cost
total_cost = total_consumption * COST_PER_LITER

# Display results
print("\nWater Consumption and Costs:")
for i in range(num_units):
    unit_consumption = consumption_per_resident * residents_per_unit[i]
    unit_cost = unit_consumption * COST_PER_LITER
    print(f"Unit {i + 1}:")
    print(f"  Water Consumption: {unit_consumption:.2f} liters")
    print(f"  Cost: {unit_cost:.2f} Tomans")

print(f"\nTotal Water Consumption: {total_consumption:.2f} liters")
print(f"Total Cost: {total_cost:.2f} Tomans")

water = float(input("enter total water (liters):"))
unit_count = int(input("who many unit in the bulding"))

number = 1 
total_living = 0 
unit_detail = []

while number <= unit_count:
    #print("unit",number,":")
    living = int(input("who many living in the unit:"))
    unit_detail.append({"unit":number,"living":living})

    total_living += living
    number += 1

consumption_per_person = water / total_living
expens_of_water = water * 500

print("avrage using water:", water)
print("avreag consumption per person:", consumption_per_person)

for unit in unit_detail:
    unit_water = consumption_per_person * unit["living"]
    unit_cost = unit_water * 500

print(f"unit: {unit['unit']}")
print(f"Personal: {unit['living']}")
print(f"unit water: {unit_water:.2f} liters")
print(f"unit cost:: {unit_cost:.2}")`
a=float(input('mizan masraf ab kl sakhteman:'))
b=int(input('sakhteman chand vahed darad?'))
l=[]
for i in range(1,b+1):
        how=int(input("vahed {} chand saken darad ?".format(i)))
        l.append(how)
 #har litr 500 tomn       
x=sum(l)        
sahm_harnafar=a/x
print(f'mizan masraf kl:{a}litr')
print('hazine kl sakhteman:{}& sahm har nafar {}'.format(a*500,sahm_harnafar))
for i in range(len(l)):
        h=(l[i]*sahm_harnafar)
        print(f'sahm vahed {i+1}={h}litr & hazine vahed{h*500}')

<< صفحه قبل 1 2 صفحه بعد >>

ارسال جواب

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

×
بستن