ፕሮጀክት፦ የሂሳብ ማካፈያ
ሙሉውን ክፍል የምናገናኝበት ጊዜ ደርሷል። የካፌ ወይም የምግብ ቤት ሂሳብን የሚያካፍል ፕሮግራም ትገነባላችሁ፦ ጠቅላላውን ሂሳብ በብር፣ ጉርሻውንና የሰዎችን ብዛት ይጠይቃል፤ ከዚያ የእያንዳንዱን ሰው ድርሻ የያዘ ንጹህ ደረሰኝ ያሳያል። በሦስት ደረጃዎች ትገነቡታላችሁ፤ ከእያንዳንዱ በኋላም ታስኬዱታላችሁ (run)፤ ከዚያ እውነተኛ የክፍያ apps ጭምር መፍታት ያለባቸውን አንድ ትንሽ የገንዘብ እንቆቅልሽ ትፈታላችሁ።
ሂሳቡ 1,850 ብር፣ ጉርሻው 10%፣ ተካፋዮቹም ሦስት ሰዎች ሲሆኑ የተጠናቀቀው ፕሮግራም የሚያሳየው ይኸውና፦
Bill total in birr: 1850
Tip percentage: 10
Number of people: 3
Bill 1,850.00 birr
Tip 185.00 birr
Grand total 2,035.00 birr
Each person 678.33 birrእያንዳንዱን ደረጃ በየኮድ ሳጥኑ ውስጥ ስሩ። መፍትሄውን ከመክፈታችሁ በፊት ራሳችሁ ሞክሩ፤ ተቸግሮ መውጣት ነው ትምህርቱ የሚገኝበት።
ደረጃ 1፦ ሒሳቡ
ያለ ምንም ጥያቄ ጀምሩ፦ ለእሴቶቹ ስም ስጡና ሒሳቡን ትክክል አድርጉ። ጉርሻው መቶኛ ነው፤ ስለዚህ የሂሳቡ 10% bill * 10 ሳይሆን bill * 10 / 100 ነው።
መልመጃ
ድርሻውን አስሉ
ስሞቹ ተዘጋጅተዋል። tip፣ grand_total እና share የሚሉ ሦስት ስሞችን ጨምራችሁ እንደዚህ አሳዩአቸው። ስለ ረጃጅሞቹ የአስርዮሽ ቦታዎች ገና አትጨነቁ።
Your code
bill = 1850
tip_percent = 10
people = 3
# ጉርሻውን፣ ጠቅላላ ድምሩንና የእያንዳንዱን ሰው ድርሻ አስሉIn the editor, press Escape then Tab to move on.
መፍትሄውን አሳይHide the solution
This is one way to solve it, not the only one. If yours prints the same thing, it works.
bill = 1850
tip_percent = 10
people = 3
tip = bill * tip_percent / 100
grand_total = bill + tip
share = grand_total / people
print("Tip:", tip)
print("Grand total:", grand_total)
print("Each person:", share)ሁለት ነገሮችን አስተውሉ። ጉርሻው 185.0፣ ማለትም ዴሲማል ቁጥር ነው፤ ምክንያቱም / ሁልጊዜ ዴሲማል ቁጥር ይሰጣል። ድርሻው ደግሞ የትኛውም የብር መጠን ሊኖረው ከሚችለው እጅግ የበዙ የአስርዮሽ ቦታዎች አሉት። ደረጃ 3 ያንን ያስተካክላል።
ደረጃ 2፦ ተጠቃሚውን መጠየቅ
አሁን ሦስቱን ቋሚ እሴቶች በጥያቄዎች ተኩ። ትምህርት 1.5ን አስታውሱ፦ ተጠቃሚው የሚጽፈው ሁሉ እንደ ጽሑፍ ይደርሳል። ከማስኬዳችሁ በፊት መቀየር ብትረሱ ምን እንደሚሆን አስቡ።
መልመጃ
ቁጥሮቹን ጠይቁ
የመጀመሪያዎቹን ሦስት መስመሮች በinput() ጥሪዎች ተኩ። ሂሳቡና ጉርሻው የአስርዮሽ ቦታ ሊኖራቸው ስለሚችል ለእነሱ float()ን፣ ለሰዎቹ ብዛት ደግሞ int()ን ተጠቀሙ። የInput ሳጥኑ 1850፣ 10 እና 3ን አስቀድሞ ይዟል።
Your code
bill = 1850
tip_percent = 10
people = 3
tip = bill * tip_percent / 100
grand_total = bill + tip
share = grand_total / people
print("Tip:", tip)
print("Grand total:", grand_total)
print("Each person:", share)In the editor, press Escape then Tab to move on.
One answer per line, given to input() in order.
መፍትሄውን አሳይHide the solution
This is one way to solve it, not the only one. If yours prints the same thing, it works.
bill = float(input("Bill total in birr: "))
tip_percent = float(input("Tip percentage: "))
people = int(input("Number of people: "))
tip = bill * tip_percent / 100
grand_total = bill + tip
share = grand_total / people
print("Tip:", tip)
print("Grand total:", grand_total)
print("Each person:", share)አንድ መቀየር ከረሳችሁ TypeError አግኝታችኋል፦ Python ጽሑፍን በቁጥር አያባዛም፣ አያካፍልምም። ስህተቱ የሚያመለክተው መቀየሩን የረሳውን መስመር ሳይሆን ሒሳቡን የሰራውን መስመር ነው፤ ስለዚህ ይህንን ስህተት ስታዩ እያንዳንዱ እሴት ከየት እንደመጣ ፈትሹ።
ደረጃ 3፦ ደረሰኙ
የመጨረሻ ደረጃ፦ ሰዎች የሚያምኑት ደረሰኝ። በትምህርት 1.4 የተማራችሁትን ተጠቀሙ፦ መለያዎቹ 14 characters ስፋት ባለው ዓምድ፣ መጠኖቹ ደግሞ በቀኝ በኩል 12 ስፋት ባለው ዓምድ፣ በሺህ መለያዎችና በሁለት የአስርዮሽ ቦታዎች (:>12,.2f)። ባዶ print() ጥያቄዎቹን ከደረሰኙ ይለያቸዋል።
መልመጃ
ደረሰኙን አስተካክሉት
ውጤቱ (output) በዚህ ገጽ ከላይ ካለው ደረሰኝ ጋር በትክክል እንዲገጥም በመጨረሻ ያሉትን ሦስት የprint መስመሮች ተኩ። ሲገጥም ከኮድ ሳጥኑ ስር ያለው ማስታወሻ ይነግራችኋል።
Your code
bill = float(input("Bill total in birr: "))
tip_percent = float(input("Tip percentage: "))
people = int(input("Number of people: "))
tip = bill * tip_percent / 100
grand_total = bill + tip
share = grand_total / people
print("Tip:", tip)
print("Grand total:", grand_total)
print("Each person:", share)In the editor, press Escape then Tab to move on.
One answer per line, given to input() in order.
መፍትሄውን አሳይHide the solution
This is one way to solve it, not the only one. If yours prints the same thing, it works.
bill = float(input("Bill total in birr: "))
tip_percent = float(input("Tip percentage: "))
people = int(input("Number of people: "))
tip = bill * tip_percent / 100
grand_total = bill + tip
share = grand_total / people
print()
print(f"{'Bill':<14}{bill:>12,.2f} birr")
print(f"{'Tip':<14}{tip:>12,.2f} birr")
print(f"{'Grand total':<14}{grand_total:>12,.2f} birr")
print(f"{'Each person':<14}{share:>12,.2f} birr")ፈትሹት
ለአንድ ኢንፑት (input) የሚሰራ ፕሮግራም ለሌሎች ላይሰራ ይችላል። የጨረሳችሁትን ፕሮግራም በእነዚህ ሁለት ቴስቶችም (test) ፈትሹት፦ በInput ሳጥኑ ውስጥ ያሉትን መስመሮች ቀይሩ፣ አስኪዱት፣ ከዚህ ካለው ውጤት ጋር character በcharacter አነጻጽሩት።
ቴስት 2 ትልቅ እራት ነው፦ 12,500 ብር፣ 15% ጉርሻ፣ አራት ሰዎች።
Bill total in birr: 12500
Tip percentage: 15
Number of people: 4
Bill 12,500.00 birr
Tip 1,875.00 birr
Grand total 14,375.00 birr
Each person 3,593.75 birrቴስት 3 1,000 ብር ነው፤ ጉርሻ የለም፤ ሦስት ሰዎች።
Bill total in birr: 1000
Tip percentage: 0
Number of people: 3
Bill 1,000.00 birr
Tip 0.00 birr
Grand total 1,000.00 birr
Each person 333.33 birrደረጃ 4፦ የጠፋችው ሳንቲም
ቴስት 3ን በጥንቃቄ ተመልከቱ። ከሦስቱ ሰዎች እያንዳንዱ 333.33 ብር ይከፍላል። ደምሩት።
ውጤቱን ገምቱ
Decide before you look. Guessing wrong is how this sticks.
share = round(1000 / 3, 2)
print(f"{share * 3:.2f}")Python prints
999.99
ሦስት ሰዎች እያንዳንዳቸው 333.33 ብር ሲከፍሉ 999.99 ብር ይሆናል፤ ከሂሳቡ አንድ ሳንቲም ያንሳል። እያንዳንዱን ድርሻ ወደ ሁለት የአስርዮሽ ቦታዎች ማጠጋጋት የሳንቲም አንድ ሦስተኛን ሦስት ጊዜ ጥሎታል።
አንድ ሳንቲም ትንሽ ናት፤ ግን በእያንዳንዱ የተካፈለ ሂሳብ ላይ አንድ ሳንቲም የሚያጣ የክፍያ app በሚሊዮኖች ክፍያዎች ውስጥ እውነተኛ ገንዘብ ያጣል። መፍትሄው የትምህርት 1.2 ደንብ ነው፦ ገንዘብን በሙሉ ሳንቲሞች ቁጠሩ። ሁሉም ተመሳሳይ ሙሉ የሳንቲም ቁጥር እንዲከፍል በ// አካፍሉ፤ % ደግሞ በትክክል ስንት እንደሚቀሩ ይነግራችኋል። ደረጃ በደረጃ ተከተሉት፦
Step through it
Press Next to run one line at a time and watch each name change.Each row is one step: the line that just ran, and every name's value after it.
| Name | Value after line 1 |
|---|---|
| grand_total | 1000.0new |
| people | not made yet |
| total_santim | not made yet |
| share_santim | not made yet |
| leftover | not made yet |
Step 1 of 5
Step 1 of 5. Line 1: grand_total = 1000.00. grand_total is now 1000.0.
| Step | Line | grand_total | people | total_santim | share_santim | leftover |
|---|---|---|---|---|---|---|
| 1 | 1 | 1000.0 | not made yet | not made yet | not made yet | not made yet |
| 2 | 2 | 1000.0 | 3 | not made yet | not made yet | not made yet |
| 3 | 3 | 1000.0 | 3 | 100000 | not made yet | not made yet |
| 4 | 4 | 1000.0 | 3 | 100000 | 33333 | not made yet |
| 5 | 5 | 1000.0 | 3 | 100000 | 33333 | 1 |
ሁሉም 33,333 ሳንቲም ይከፍላል፤ 1 ሳንቲም ይቀራል። አንድ ሰው ይከፍላታል፤ አሁን ድርሻዎቹ ሲደመሩ በትክክል 1,000 ብር ይሆናሉ።
መልመጃ
የቀረችውን ሳንቲም አካፍሉ (ተጨማሪ መልመጃ)
grand_total ከተሰላ በኋላ የሳንቲሙን ስሌት ወደ ፕሮግራማችሁ ጨምሩ። ሁሉም የሚከፍለውን፣ ድምሩ ትክክል እንዲሆንም አንድ ሰው ምን ያህል ተጨማሪ እንደሚከፍል አሳዩ። ለቴስት 3 የውጤቱ መጨረሻ እንዲህ መሆን አለበት፦
Each person pays 333.33 birr
One person pays 0.01 birr moreYour code
grand_total = 1000.00
people = 3In the editor, press Escape then Tab to move on.
መፍትሄውን አሳይHide the solution
This is one way to solve it, not the only one. If yours prints the same thing, it works.
grand_total = 1000.00
people = 3
total_santim = round(grand_total * 100)
share_santim = total_santim // people
leftover = total_santim % people
print(f"Each person pays {share_santim / 100:,.2f} birr")
print(f"One person pays {leftover / 100:,.2f} birr more")እዚያ round(grand_total * 100) ዋጋ አለው፦ ዴሲማል ቁጥር በ100 ሲባዛ ከሙሉ ቁጥሩ በጥቂቱ ሊያንስ ይችላል፤ round ከመቁጠራችሁ በፊት ይመልሰዋል።
ዋና ዋና ነጥቦች
- በትንንሽ ደረጃዎች ገንቡ፤ ከእያንዳንዱ በኋላም አስኪዱ፦ መጀመሪያ ሒሳብ፣ ከዚያ ኢንፑት፣ ከዚያ አቀራረብ።
- ከ
input()የሚመጣውን እያንዳንዱን ቁጥር ቀይሩ፤ የጎደለ መቀየር በኋላ፣ ሒሳቡ በሚሰራበት ቦታ ይታያል። :>12,.2fበሺህ መለያዎችና በሁለት የአስርዮሽ ቦታዎች የሚሰለፉ መጠኖችን ይሰጣል።- ከአንድ በላይ በሆኑ ኢንፑቶች ፈትሹ፤ እንደ እኩል የማይካፈል ሂሳብ ያሉ አስቸጋሪዎቹንም ጨምሮ።
- ለገንዘብ ምንም ነገር እንዳይጠፋ ሙሉ ሳንቲሞችን በ
//እና በ%ቁጠሩ።