برنامج تحويل العملات تم بنجاح

الحمد لله وصلت للحل في أقوى تحدي…
مشروع تحويل العملات تعلمت منه الكثير…بحثت عن الكثير وفكرت كثيرا من اجل النجاح في التحدي…
الفلو شارت أخذ مني يوم كامل…
الحسابات الرياضية عانيت منها لأننا لا نتكلم نفس اللغة مع الرياضيات للأسف. .
الكود كله أخذ مني يوم كامل…
وأخيرا فهمت المعادلة وتعلمت طرق جديدة في التفكير والبحث…استطعت بناء البرنامج من الصفر انطلاقا من رحلة من التعلم والتفكير والبحث…
طبعا هذه طريقتي الخاصة ومجددا تبدوا معقدة مقارنة مع طريقة الأستاذ…لكن لا بأس في فهذا يعني أنه اصبح لدي طريقتان لوصول الى نفس النتيجة…
عملت وظيفة لطباعة تلك الرسومات وأيضا طباعة القاموس.
وظيفة لحساب و طباعة التحويل الى الدولار، واخرى للتحويل من الدولار…واخرى للتحويل بين بقية العملات…كذلك إذا أدخل المستخدم عملة غير موجودة يتم إلغاء التحويل مباشرة دون طلب الكمية…
أنا سعيد جدا…
الحمد لله…

import os
import time

def clear_screen():
    os.system ('cls' if os.name == 'nt' else 'clear')


currency = {
    "USD" : 1,
    "EUR": 0.85,
    "DZ" : 220,
    "EGP": 30.9,
    "RNB" : 6.5,
    }


def bank():

    print (r"""
    ||====================================================================||
    ||//$\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//$///||
    ||(100)=================| THE ALGERIAN BANK TARNSACTION |========(100)||
    ||//$//        ~         '------========--------'                //$//||
    ||<< /        /$\              // ____ //                         \ >>||
    ||>>|  12    //L//            // ///..) //        F4120251997   12 |<<||
    ||<<|        // //           || <||  >\  ||                        |>>||
    ||>>|         \$/            ||  $$ --/  ||        One Hundred     |<<||
||====================================================================||>>||
||//$///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//$//||<<||
||(100)==================|THE ALGERIAN BANK TARNSACTION |========(100)||>>||
||//$//        ~         '------========--------'                //$//||/\||
||<< /        /$\              // ____ //                         \ >>||))||
||>>|  12    //L//            // ///..) //         F4120251997  12 |<<||//||
||<<|        // //           || <||  >\  ||                        |>>||==||
||>>|         \$/            ||  $$ --/  ||        One Hundred     |<<||==||
||<<|      F4120251997       *//  |\_/  //* series                 |>>||
||>>|  12                     *//___\_//*   1989                   |<<||
||<<\      Treasurer     ______/  CODER \________     Secretary 12 />>||
||//$\                 ~|UNITED STATES OF MONEY|~                 /$//||
||(100)===================  ONE HUNDRED DOLLARS =================(100)||
||//$//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///$//||
||====================================================================||     
    """)
    
    for key in currency:
        print (f"{key} : {currency[key]}")
    
    print ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")


def convert_to_USD (amount,rate):
    """
    تحويل أي عملة إلى الدولار، بتقسيم الكمية على سعر الصرف."""

    result = round ( (amount / rate),4 )
    change_rate = round ( (1 / rate),4 )
    print (f"\nCharge rate: 01 {user_currency} = {change_rate} USD")
    print (f"\n{amount} {user_currency} is equal to {result} USD")


def convert_from_USD (amount,rate):
    """
    .تحويل الدولار إلى أي عملة، اضرب الكمية في سعر الصرف"""
    result = round ( (amount * rate),4 )

    print (f"\nCharge rate: 01 USD = {rate} {user_target_currency}")
    print (f"\n{amount} USD is equal to {result} {user_target_currency}")


def any_currency (amount,usdrate,targetrate):
    """
    التحويل ما بين مختلف العملات من خلال الدولار كعملة وسيطة...
    يتم تحويل العملة الأصلية الى الدولار والنتيجة تحول إلى العملة المستهدفة"""
    
    result = amount/usdrate
    result = round ( (result * targetrate),4 )
    print (f"\nChange rate: 01 {user_currency} = " 
           f"{round ( (1/usdrate),4 )} USD = " 
           f"{round( ((1/usdrate) * targetrate ),4)} {user_target_currency}")
    print (f"\n{amount} {user_currency} is equal to {result} {user_target_currency}")


def currency_not_exist():
    print ("Checking the currency....Please wait.")
    time.sleep(2)
    print (f"Currency ({user_currency}) is not supported at our bank!")
    time.sleep(2)


# بداية البرنامج
while True:
    clear_screen()
    bank()

    user_currency = input ("\nChoose your currency to convert from: ").upper()
    user_target_currency = None

    # عملة غير مدعومة
    if user_currency not in currency:
        currency_not_exist()
        continue

    else:

        while True:
            user_amount = float ( input ("\nEnter the amount: ") )

            if input (f"You entered {user_amount} {user_currency}. confirme (y/n): ").lower() != 'y':
                continue
            else:
                user_target_currency = input ("\nChoose a currency to convert to: ").upper()
                
                if user_target_currency not in currency:
                    break

                # العملة المستهدفة مدعومة
                else:
                    clear_screen()
                    bank()
                    print ("\nAnalyzing your request...Please wait.")
                    time.sleep(2)
                    print ("Checking for USD's best rates available...Please wait.")
                    time.sleep(2)
                    print (f"Checking for a discount price for {user_target_currency}...Please wait.")
                    time.sleep(2)
                    clear_screen()
                    print (f"Preparing the deal from {user_currency} to {user_target_currency}...Please wait.")
                    time.sleep(2)

                    if user_currency == 'USD':
                        convert_from_USD (user_amount,currency[user_target_currency])
                    elif user_target_currency == 'USD':
                        convert_to_USD (user_amount,currency[user_currency]) 
                    else:
                        any_currency (user_amount,currency[user_currency],currency[user_target_currency])
                    break

    # العملة المستهدفة غير مدعومة
    if user_target_currency not in currency:
        currency_not_exist()
        continue
    
    if input ("\nDo you accept this transaction? (y/n): ").lower() == 'y':
        print ("Transaction successfull.")
    else:
        print ("Canceling....")
    
    if input ("\nDo you want to make another transaction? (y/n): ").lower() == 'y':
        continue
    else:
        print ("Exiting...")
        break

إعجابَين (2)

ما شاء الله تبارك الرحمن…أحسنت شي بيدعو للفرح والحماس …الله يوفقك ويثبتك ومنتظرين إبداعاتك المستقبلية✌️

إعجابَين (2)

الله يعطيك ألف عافية أخي :heartbeat:

3 إعجابات

شكرا لك…
إن شاء الله…
ربنا يوفقنا جميعا.

إعجاب واحد (1)

شكرا على تعليقك الرائع

إعجابَين (2)