مشاركة حلول: مهمة سحب الأموال آلياً

مرحباً جميعاً

المهمة المطلوبة

بإمكانك الإطلاع على المهمة المطلوبة من هنا

كيفية كتابة الأكواد في المنتدى

  • إذا كان لديك كيبورد فرنسي, اضغط على alt gr و 7 لكتابة الرمز `

4 Likes
# allowed papers: 100, 50, 10, 5, and rest of request

money = 500
request = 277

if request <= money:
	if request > 0 :
		while request > 0 :
			if request >= 100 :
				request -= 100
				print("give 100")
			elif request < 100 and request >= 50 :
				request -= 50
				print("give 50")
			elif request < 50 and request >= 10 :
				request -= 10
				print("give 10")
			elif request < 10 and request >= 5 :
				request -= 5
				print("give 5")
			else:
				print("give",request)
				break
	else:
		print("please try again")
else:
	print("not enough money")
Summary

This text will be hidden

2 Likes
money = 500
def bank(request):
    if request <= money:
        if request > 0:
            while request > 0:
                if request >= 100:
                    request -= 100
                    print("donner 100")
                elif request < 100 and request >= 50:
                    request -= 50
                    print("donner 50")
                elif request < 50 and request >= 10:
                    request -= 10
                    print("donner 10")
                elif request < 10 and request >= 5:
                    request -= 5
                    print("donner 5")
                else:
                    print("donner" , request)
                    break
        else:
            print("impossible de retirer ",request,"$ veuillez réessayer")
    else:
        print("votre solde est insuffisant pour effectuer cette operation. veuillez recharger votre compte")
        
bank(277)
2 Likes
money = 500
def bank(request):
    if (request <= money):
        if (request > 0):
            while request > 0:
                if (request >= 100):
                    request -= 100
                    print("donner 100")
                elif (request < 100) & (request >= 50):
                    request -= 50
                    print("donner 50")
                elif (request < 50) & (request >= 10):
                    request -= 10
                    print("donner 10")
                elif (request < 10 )& (request >= 5):
                    request -= 5
                    print("donner 5")
                else:
                    print("donner" , request)
                    break
        else:
            print("impossible de retirer ",request,"$ veuillez réessayer")
    else:
        print("votre solde est insuffisant pour effectuer cette operation. veuillez recharger votre compte")
        
bank(0)
2 Likes

@kaabi_otman
@yahya-alshammout

عمل رائع :+1:

2 Likes
money = 500
request = 277
if money > request:
	while request >0:
		if request >= 100:
			request -= 100
			print("give "+str(100))
		elif request >= 50:
			request -= 50
			print("give " + str(50))	
		elif request >= 10:
			request -= 10
			print("give " + str(10))
		elif request >= 5:
			request -= 5
			print("give " + str(5))
		else :
			request -= 2
			print("give " + str(2))			
else:
	print("Not avalible")
1 Like

السلام عليكم
إليكم مشاركتي

money = 500
blacknotes = [100, 50, 10, 5, 2]
def giveMoney(request):
    if request > money:
        print('Sorry! You have\'nt enough money')
    elif request < 0:
        print("Please, Enter more than 0!")

    else:
        while request > 0:
            if request >= blacknotes[0]:
                print('give '+str(blacknotes[0]))
                request-= blacknotes[0]
            elif request < blacknotes[0] and request >= blacknotes[1]:
                print('give '+str(blacknotes[1]))
                request-= blacknotes[1]
            elif request < blacknotes[1] and request >= blacknotes[2]:
                print('give '+str(blacknotes[2]))
                request-= blacknotes[2]
            elif request < blacknotes[2] and request >= blacknotes[3]:
                print('give '+str(blacknotes[3]))
                request-= blacknotes[3]
            elif request < blacknotes[3] and request >= blacknotes[4]:
                print('give '+str(blacknotes[4]))
                request-= blacknotes[4]
            elif request < blacknotes[4]:
                break

giveMoney(277)
1 Like

عمل ممتاز @asmaa_salih @Adetech :+1:

2 Likes
money = 500
request=277

def subtract(request):
    while request >= 100:
        request =request-100
        print("give 100")

    while request<100 and request>=50:
        request=request-50
        print ("give 50")

    while request<50 and request>=10:
        request=request -10
        print("give 10")

    while request<10 and request>=5:
        request=request-5
        print("give 5")
    if request!=0:
        print ("give "+str(request))


subtract(request)
subtract(100)
subtract(2120)
subtract(10)

1 Like

here is mine

money = 500
request=358
allowed = [100, 50, 10, 5]

if request <=500:
    while request > 5:
        for i in allowed :
            while request >= i:
                print (i)
                request -= i
    if request >0:
        print (request)

else:
    print('Sorry, no enough money')
1 Like
money=500

request= 277

if request<=money:
    while request>0:
        if request>=100:
            request-=100
            print('give :100')
        elif request>=50:
            request-=50
            print('give :50')
        elif request>=10:
            request-=10
            print('give :10')
        elif request>=5:
            request-=5
            print('give :5')
        else:

            print('give :',request)
            request-=request

else:
    print("you don't have enough money")

1 Like

from _ast import If

amount: int = 1000

print(“Enter the cash”)
cash =int(input())

If (cash <= 0 )
print(“invalid number”)

If (cash > amount)
print(“there is no efficient money in the machine”)

while (cash >= 100):
print(“give cash 100”)
cash-=100
amount-=100

while (cash >= 50 ):
print ( “give cash 50” )
cash -= 50
amount -= 50

while (cash >= 10 ):
print(“give cash 10”)
cash-=10
amount-=10

while (cash >= 5):
print(“give cash 10”)
cash-=5
amount-=5

while (cash > 0 ):
print(“give cash 2”)
cash-=2
amount-=2
print("cash , amount ",cash ,amount)

1 Like

مرحبا محمد

لو ممكن تقوم بتنسيق الكود حسب ماهو موضح بالفيديو بالاعلى لكي نستطيع قراءة الاكواد

money=500
print("welcome ")
request=int(input("please enter your money:"))
if (money>request):
    while request>0:
        if request>=100:
            request-=100
            print("give",100)
        elif request>=50:
            request -= 50
            print("give",50)
        elif request>=10:
            request -= 10
            print("give",10)
        elif request>=5:
            request -= 5
            print("give", 5)
        else:
            print("give",request)
            request-=request
else:
    print("sorry , there is no enough money")

3 Likes

عمل رائع يا فوزي… انتقل للمهمة التالية :+1:

1 Like
# ATM Cash
balance = 500
currency_unit = { 100:0, 50:0, 10:0 , 5:0, 1:0 }

def monyCount(key):
    value = currency_unit.get(key)
    currency_unit.update({key: value + 1})

def giveMoney(request):
    print("Your ATM balance is: " + str(balance) + "$")
    cash_categories = currency_unit.keys()
    cash_categories.sort(reverse = True)

    while request > 0 and request < balance:
        if request >= cash_categories[0]:
            print('Give '+str(cash_categories[0]))
            monyCount(cash_categories[0])
            request -= cash_categories[0]
        elif request < cash_categories[0] and request >= cash_categories[1]:
            print('Give '+str(cash_categories[1]))
            monyCount(cash_categories[1])
            request -= cash_categories[1]
        elif request < cash_categories[1] and request >= cash_categories[2]:
            print('Give '+str(cash_categories[2]))
            monyCount(cash_categories[2])
            request -= cash_categories[2]
        elif request < cash_categories[2] and request >= cash_categories[3]:
            print('Give '+str(cash_categories[3]))
            monyCount(cash_categories[3])
            request -= cash_categories[3]
        elif request < cash_categories[3] and request >= cash_categories[4]:
            print('Give '+str(cash_categories[4]))
            monyCount(cash_categories[4])
            request -= cash_categories[4]
        else:
            break
    
    if request > balance:
        print('You have not enough money !!')
    else:
        print(currency_unit)
        
giveMoney(277)
1 Like

عمل رائع جداً يا لؤي… ما شاء الله :+1:

فقط تجنب استعمال break (لأن الشرط بجاتب while سيفي بالغرض).

وأيضاً ستقوم بتطويره أكثر في المهام القادمة, هناك من قام بكود مشابه بشكل جميل :wink:

mony=500
request=277

if request>=500:
    if request>=100:
         request -= request
         print("give 100")

    elif request >= 50:
         request -= 50
         print("give 50")

    elif request >= 10:
         request -=10
         print("give 10") 

    elif request >=5:
        request -= 5
        print("give 5")

    elif request >=2 :
         request -=2
         print("give 2")

    else:
        print("no found else..")             

1 Like

بعد التعديل

mony=500
request=277

while request>0:
    if request>=100:
         request = request- 100
         print("give 100")

    elif request >= 50:
         request = request- 50
         print("give 50")

    elif request >= 10:
         request = request-10
         print("give 10") 

    elif request >=5:
        request = request- 5
        print("give 5")

    elif request >=2 :
         request = request-2
         print("give 2")

    else:
        print("no found else..")             

عمل جيد يا امينة… فقط ينقص اضافة حلقة while لتكرار عملية السحب :wink: