Вопрос задан 16.06.2023 в 13:50. Предмет Информатика. Спрашивает Александрова Александра.

Python Сделать программу, которая переводит рубли в доллары, евро, фунты. Курсы валют задаются

пользователем. Предусмотреть возможность обратного перевода из долларов (евро, фунтов) в рубли.
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Быков Тимофей.

Программа:

Python:

if input('Хотите вписать текущий курс самостоятельно (да/нет)? ') == 'да':

   RubToDollar = float(input('Рубль к доллару: '))

   RubToEuro = float(input('Рубль к евро: '))

   RubToFunt = float(input('Рубль к фунту: '))

else:

   RubToDollar = 0.013  # курс на 18.02.22

   RubToEuro = 0.011

   RubToFunt = 0.0095

cash = int(input('Введите количество денег: '))

currency = input('В какой валюте введены деньги (руб, евро, доллар, фунт)? ')

match currency:

   case "руб":

       print(f'{cash} руб в долларах: {int(cash * RubToDollar)}')

       print(f'{cash} руб в евро: {int(cash * RubToEuro)}')

       print(f'{cash} руб в фунтах: {int(cash * RubToFunt)}')

   case "евро":

       print(f'{cash} евро в рублях: {int(cash / RubToEuro)}')

   case "доллар":

       print(f'{cash} доллар(-ов) в рублях: {int(cash / RubToDollar)}')

   case "фунт":

       print(f'{cash} фунт(-ов) в рублях: {int(cash / RubToFunt)}')

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Python Currency Converter Program

To create a program in Python that converts Russian rubles to dollars, euros, and pounds, and also allows for the reverse conversion, you can use the following approach:

1. User-Defined Exchange Rates: - Prompt the user to input the exchange rates for converting rubles to dollars, euros, and pounds. - Store these exchange rates for later use in the program.

2. Conversion Functions: - Create functions to perform the currency conversions in both directions: - One function to convert rubles to dollars, euros, and pounds using the user-defined exchange rates. - Another function to convert dollars, euros, and pounds back to rubles using the inverse of the user-defined exchange rates.

3. Sample Python Code: - Here's a simple example of how the Python code might look:

```python def rubles_to_foreign_currency(rubles, exchange_rate): foreign_currency = rubles / exchange_rate return foreign_currency

def foreign_currency_to_rubles(foreign_currency, exchange_rate): rubles = foreign_currency * exchange_rate return rubles

# Prompt user for exchange rates rubles_to_dollars_rate = float(input("Enter the exchange rate from rubles to dollars: ")) rubles_to_euros_rate = float(input("Enter the exchange rate from rubles to euros: ")) rubles_to_pounds_rate = float(input("Enter the exchange rate from rubles to pounds: "))

# Convert rubles to foreign currency rubles_amount = float(input("Enter the amount in rubles: ")) dollars_amount = rubles_to_foreign_currency(rubles_amount, rubles_to_dollars_rate) euros_amount = rubles_to_foreign_currency(rubles_amount, rubles_to_euros_rate) pounds_amount = rubles_to_foreign_currency(rubles_amount, rubles_to_pounds_rate)

print(f"{rubles_amount} rubles is equal to {dollars_amount} dollars, {euros_amount} euros, and {pounds_amount} pounds.")

# Convert foreign currency back to rubles foreign_amount = float(input("Enter the amount in foreign currency: ")) currency_type = input("Enter the currency type (dollars, euros, or pounds): ")

if currency_type == "dollars": rubles_amount = foreign_currency_to_rubles(foreign_amount, rubles_to_dollars_rate) elif currency_type == "euros": rubles_amount = foreign_currency_to_rubles(foreign_amount, rubles_to_euros_rate) elif currency_type == "pounds": rubles_amount = foreign_currency_to_rubles(foreign_amount, rubles_to_pounds_rate)

print(f"{foreign_amount} {currency_type} is equal to {rubles_amount} rubles.") ```

This code allows the user to input the exchange rates and amounts, and then performs the currency conversions accordingly.

Note: The actual implementation may vary based on specific requirements and error handling.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос