I’m working on a little currency converter script that asks for a user input to select the currency (GBP or USD) and can’t figure out how to get it to function as expected.
What I want to happen is:
input > do you want to convert from dollars or pounds
- if they select dollars, do dollar calc
- if they select pounds, do pounds calc.
- if they input something else, loop back and ask again
name = input('please enter your name:')
while name == "" :
name= input('Please enter your name: ')
The name loop works as expected, but when I try to get the user to select a currency using the below block:
- if they input nothing, it still ignores the else condition
- even if they input ‘pounds’ or gbp etc, it still asks how many dollar to convert.
I’m struggling to understand if it’s to do with indents, or something else I’m missing.
print('hello',name)
while True:
currency_selector = input('do you want to convert from dollars or pounds?')
if currency_selector == 'dollars' or '$' or 'USD' or 'Usd' or 'usd' or 'United States Dollars' or 'united states dollars':
dollar_value = int(input('How many Dollars do you want to convert to pounds?'))
dollar_to_pounds = dollar_value * 0.81 #market rate 16/9/23
print('$', dollar_value,'in GBP is', '£', round(dollar_to_pounds,2),)
break
elif currency_selector == 'pounds' or 'Pounds'or'GBP' or 'gbp' or 'Gbp' or '£' :
pound_value = int(input('How many Pounds do you want to convert to Dollars?'))
pounds_to_dollars = pound_value * 1.24 #market rate 16/9/23
print('£', pound_value,'in US Dollars is', '£', round(pounds_to_dollars,2),)
break
else:
print('please enter either USD or GBP')
1