The coding of the exchange rate calculator using for door and tuple is blocked, so please give me a hint!

Asked 2 years ago, Updated 2 years ago, 79 views

mymoney = input ("ex. $100:")
mymoney_sep = mymoney.split()
mymoney_flo = float(mymoney_sep[0])

toexch = input ("Types of currency to exchange (ex. dollar, yen, euro, yuan, won):")

# exchange = {'usd': 1167, 'jpy': 10.96, 'eur': 1268, 'cny': 171, 'krw':1} #I tried to write a dictionary but gave up
exchange = (1167, 10.96, 1268, 171, 1)

for i in exchange:
    if mymoney_sep[1] == "dollar" and toexch == "yen":
        result = i * int(mymoney_sep[0])
        print(result)

Hello! Please give us a hint! I'm trying to code the exchange rate

Using for statement and tuple, dollar, yen, euro, yuan, won I'm going to make it by entering the currency unit that I'm going to change I'm trying to do it without adding a new function

Dollar now - > Dollar, Yen, Euro, Yuan, Cause status.. I don't know how to move on I don't think it's indexed in i?!

Please give us a hint!

for tuple python

2022-09-20 08:47

2 Answers

I can calculate how much a dollar costs in the code you gave me. So how do you calculate how much yen a dollar is? The exchange rate of 1 won is 1 won, and the rest of the currency seems to be defined based on the won. If so:

I should always go through the second step. This will cover the number of cases.

The arithmetic of step 2 may be a little confusing, but I think it's a problem that can be solved at the level of the questioner, so I'll skip it. I'll leave you with an application task instead. Do you understand that there is no need to define the exchange rate of the "won" somewhere else according to follow the logic above? Just think!

You said, "i doesn't even seem to index." It can't be. exchange[i] is a value available. It's just that the code you gave us isn't taking advantage of it'

exchange = (1167, 10.96, 1268, 171, 1)

The tuple above is dollar, yen in order from the front... I'm not telling you what to do. So you can't exchange money with just this tuple. You can do it if you pair up with something.

# Try executing the following code.
exchange = (1167, 10.96, 1268, 171, 1)
currencies = ('dollar', 'yen', 'euro', 'people's currency', 'won') # Oops, 1 looks like the renminbi exchange rate.

# Let's say you've received the input.
mymoney_sep = [100, "dollar"]

# Investigating the enumerate() function is left as a homework Make sure to study!
for i, currency in enumerate(currencies) :
    if currency is mymoney_sep[1] :
        rate = exchange[i] # I'm in the middle of talking about current and suddenly exchange comes out.
        print(rate)
        print(mymoney_sep[0])

Oh, but this is really uncomfortable. It's ugly. For some reason, I think the dictionary type is for use at times like this.

mymoney_sep= [100, 'dollar']

# It's much cooler.
currencyToWonRates = {
    'Dollar': 1000.0,
    'N': 10.96,
    Euro: 1268.0,
    People's money: 171.0,
    'Won': 1.0, #. It turns out that 1 is definitely the won's exchange rate.
}

# Not only is it cool, but it's more organized.
for currency in currencyToWonRates :
    if currency is mymoney_sep[1] :
        print(currenityToWonRates[currenity]) # Now we can only talk about currenity.

I think this is going to be an excessive hint! Way to go!


2022-09-20 08:47

mymoney = input("exchange amount:")
mymoney_sep = mymoney.split()
mymoney_flo = float(mymoney_sep[0])

toexch = input ("Currency type to exchange: ")

exchange_rate = (1167, 10.96, 1268, 171, 1)
currency = ('dollar', 'yen', 'euro', 'yuan', 'won')

for i, currency_item in enumerate(currency):
    if currency_item == mymoney_sep[1]:
        exchange_to_won = exchange_rate[i] * mymoney_flo
        # # print(exchange_to_won)
        # # print(mymoney_sep[0])
for i, currency_item in enumerate(currency):
    if currency_item == toexch:
        result = exchange_to_won / exchange_rate[i]
        print(result)

That's it!


2022-09-20 08:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.