473,659 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

line shift? (baby steps 2)

I have done a small currency calculator. It works and I'm very glad.
But...I'd like to have a line shift if user types a wrong choice.
Please, look at the code and output example down here:

# -*- coding: ISO-8859-1 -*-
import string

eudk_currency= 7.47
dkeu_currency= 0.13
usdk_currency= 5.93
dkus_currency= 0.16
euus_currency= 1.19
useu_currency= 0.78

currency_choice = raw_input("Plea se type DK if you want convert to DKK,
EU if you want to convert to €: ")
currency_str= str(currency_ch oice).upper()

while currency_str != "EUDK" and currency_str != "DKEU" and
currency_str != "USDK" and currency_str != "DKUS"\
and currency_str != "EUUS" and currency_str!= "USEU":
currency_choice = raw_input("Sorr y. At the moment we only support
DKK, Euro and Dollars." + "\n" \
"Type DKEU if you want convert from DKK to €," + "\n" \
"EUDK if you want to convert from DKK to €," + "\n" \
"DKUS if you want to convert from DKK to $," + "\n" \
"USDK if you want to convert from $ to DKK," + "\n"
"EUUS if you want to convert from € to $," + "\n"\
"and USEU if you want to convert from $ to €: ")
currency_str= str(currency_ch oice).upper()

amount_int= input("Please type the amount you wish to convert: ")

if currency_str == "DKEU":
result= amount_int* dkeu_currency
print amount_int, "Danish Crowns correspond to", result, "Euro."

if currency_str == "EUDK":
result= amount_int* eudk_currency
print amount_int, "Euro correspond to", result, "Danish Crowns."

if currency_str == "USDK":
result= amount_int* usdk_currency
print amount_int, "Dollars correspond to", result, "Danish Crowns."

if currency_str == "DKUS":
result= amount_int* dkus_currency
print amount_int, "Danish Crowns correspond to", result, "Dollars."

if currency_str == "EUUS":
result= amount_int* euus_currency
print amount_int, "Euro correspond to", result, "Dollars."

if currency_str == "USEU":
result= amount_int* useu_currency
print amount_int, "Dollars correspond to", result, "Euro."
#CODE END

OUTPUT:

Please type DK if you want convert to DKK, EU if you want to convert
to €: sdsd
Sorry. At the moment we only support DKK, Euro and Dollars.
Type DKEU if you want convert from DKK to €,
EUDK if you want to convert from DKK to €,
DKUS if you want to convert from DKK to $,
USDK if you want to convert from $ to DKK,
EUUS if you want to convert from € to $,
and USEU if you want to convert from $ to €: usdk
Please type the amount you wish to convert: 99
99 Dollars correspond to 587.07 Danish Crowns.

How do I get a line shift before (and/or) after the "Sorry....A t the
moment"), so the output is something like:

Please type DK if you want convert to DKK, EU if you want to convert
to €: sdsd

Sorry. At the moment we only support DKK, Euro and Dollars.
Type DKEU if you want convert from DKK to €,
EUDK if you want to convert from DKK to €,
DKUS if you want to convert from DKK to $,
USDK if you want to convert from $ to DKK,
EUUS if you want to convert from € to $,
and USEU if you want to convert from $ to €: usdk
Please type the amount you wish to convert: 99
99 Dollars correspond to 587.07 Danish Crowns.

OR

Please type DK if you want convert to DKK, EU if you want to convert
to €: sdsd

Sorry. At the moment we only support DKK, Euro and Dollars.

Type DKEU if you want convert from DKK to €,
EUDK if you want to convert from DKK to €,
DKUS if you want to convert from DKK to $,
USDK if you want to convert from $ to DKK,
EUUS if you want to convert from € to $,
and USEU if you want to convert from $ to €: usdk
Please type the amount you wish to convert: 99
99 Dollars correspond to 587.07 Danish Crowns.

???
Thank you for your patience! :-)
Jul 18 '05 #1
6 1955
On 23 Aug 2004 05:12:30 -0700, Artemisio <ca*******@hotm ail.com> wrote:
I have done a small currency calculator. It works and I'm very glad.
But...I'd like to have a line shift if user types a wrong choice.


A simple "print" with no arguments should display the blank line you want:

while currency_str != "EUDK" and currency_str != "DKEU" and
currency_str != "USDK" and currency_str != "DKUS"\
and currency_str != "EUUS" and currency_str!= "USEU":
print
currency_choice = raw_input("Sorr y. At the moment we only support
DKK, Euro and Dollars." + "\n" \
"Type DKEU if you want convert from DKK to €," + "\n" \
"EUDK if you want to convert from DKK to €," + "\n" \
"DKUS if you want to convert from DKK to $," + "\n" \
"USDK if you want to convert from $ to DKK," + "\n"
"EUUS if you want to convert from € to $," + "\n"\
"and USEU if you want to convert from $ to €: ")
currency_str= str(currency_ch oice).upper()

Or you can add an extra "\n" at the beginning of your "Sorry" string.
Jul 18 '05 #2
Artemisio wrote:
I have done a small currency calculator. It works and I'm very glad.
But...I'd like to have a line shift if user types a wrong choice.
Please, look at the code and output example down here:

# -*- coding: ISO-8859-1 -*-
import string

eudk_currency= 7.47
dkeu_currency= 0.13
usdk_currency= 5.93
dkus_currency= 0.16
euus_currency= 1.19
useu_currency= 0.78


As a hint not pertaining to your actual problem: Use a dictionary to
store the values, like this:

currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) }

Then you do not have to do if statements like this

if currency_str == "DKEU":
result= amount_int* dkeu_currency
print amount_int, "Danish Crowns correspond to", result, "Euro."

(...)

You can directly use the input string as index into the dictionary:

result = amount_int * currencies[currency_str]
print (...)

Reinhold

--
Wenn eine Linuxdistributi on so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems " ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix .linux.misc
Jul 18 '05 #3
> As a hint not pertaining to your actual problem: Use a dictionary to
store the values, like this:

currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) }

Then you do not have to do if statements like this

if currency_str == "DKEU":
result= amount_int* dkeu_currency
print amount_int, "Danish Crowns correspond to", result, "Euro."

(...)

You can directly use the input string as index into the dictionary:

result = amount_int * currencies[currency_str]
print (...)

I was bored waiting on a compile so I hacked this up. It adds the \n and the
Please enter conversion type line and uses the previous poster's comment on
the using a dictionary.
I added the conversion output text by makeing the value a list that is the
conversion and the text to display for the answer (I made them shorter
because I was lazy to type all the information). I also made the conversion
from US to EU more in line with the EUUS because I used those for testing
and the results were not coming out the same (course I am sure there is some
slack in there somewhere for the bank taking its share of the proceeds :) )
Not sure if there is a slicker way to do the conversion/message - I am
relatively new to Python as well, so my code still ends up looking like C++
lots of the time.

import string

currency = {"EUDK":(7.47," ? to DKK"),
"DKEU":(0.13,"D KK to ?"),
"USDK":(5.9 3, "$ to DKK"),
"DKUS":(0.1 6, "DKK to $"),
"EUUS":(1.1 9, "? to $"),
"USEU":(0.8 4, "$ to ?")}

while(1):
currency_choice = raw_input("\nPl ease enter conversion type or 'Exit':
")
currency_str= str(currency_ch oice).upper()

if currency_str == "EXIT":
break
if currency.has_ke y(currency_str) :
amount_int= input("Please type the amount you wish to convert: ")
result = amount_int * currency[currency_str][0]
print currency[currency_str][1], " ", amount_int, " = ", result
else:
print("Sorry. At the moment we only support DKK, Euro and Dollars."
+ "\n" \
"Type DKEU if you want convert from DKK to ?," + "\n" \
"EUDK if you want to convert from DKK to ?," + "\n" \
"DKUS if you want to convert from DKK to $," + "\n" \
"USDK if you want to convert from $ to DKK," + "\n"
"EUUS if you want to convert from ? to $," + "\n"\
"and USEU if you want to convert from $ to ?")


Jul 18 '05 #4
Reinhold Birkenfeld <re************ ************@wo lke7.net> wrote in message news:<2o******* *****@uni-berlin.de>...
Artemisio wrote:
I have done a small currency calculator. It works and I'm very glad.
But...I'd like to have a line shift if user types a wrong choice.
Please, look at the code and output example down here:

# -*- coding: ISO-8859-1 -*-
import string

eudk_currency= 7.47
dkeu_currency= 0.13
usdk_currency= 5.93
dkus_currency= 0.16
euus_currency= 1.19
useu_currency= 0.78


As a hint not pertaining to your actual problem: Use a dictionary to
store the values, like this:

currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) }

Then you do not have to do if statements like this

if currency_str == "DKEU":
result= amount_int* dkeu_currency
print amount_int, "Danish Crowns correspond to", result, "Euro."

(...)

You can directly use the input string as index into the dictionary:

result = amount_int * currencies[currency_str]
print (...)

Reinhold


Great! Thank you pals! I'll have a closer look to your suggestion
Reinhold, it seems a slick way to do the same thing
Jul 18 '05 #5
> I was bored waiting on a compile so I hacked this up. It adds the \n and the
Please enter conversion type line and uses the previous poster's comment on
the using a dictionary.
I added the conversion output text by makeing the value a list that is the
conversion and the text to display for the answer (I made them shorter
because I was lazy to type all the information). I also made the conversion
from US to EU more in line with the EUUS because I used those for testing
and the results were not coming out the same (course I am sure there is some
slack in there somewhere for the bank taking its share of the proceeds :) )
Not sure if there is a slicker way to do the conversion/message - I am
relatively new to Python as well, so my code still ends up looking like C++
lots of the time.

import string

currency = {"EUDK":(7.47," ? to DKK"),
"DKEU":(0.13,"D KK to ?"),
"USDK":(5.9 3, "$ to DKK"),
"DKUS":(0.1 6, "DKK to $"),
"EUUS":(1.1 9, "? to $"),
"USEU":(0.8 4, "$ to ?")}

while(1):
currency_choice = raw_input("\nPl ease enter conversion type or 'Exit':
")
currency_str= str(currency_ch oice).upper()

if currency_str == "EXIT":
break
if currency.has_ke y(currency_str) :
amount_int= input("Please type the amount you wish to convert: ")
result = amount_int * currency[currency_str][0]
print currency[currency_str][1], " ", amount_int, " = ", result
else:
print("Sorry. At the moment we only support DKK, Euro and Dollars."
+ "\n" \
"Type DKEU if you want convert from DKK to ?," + "\n" \
"EUDK if you want to convert from DKK to ?," + "\n" \
"DKUS if you want to convert from DKK to $," + "\n" \
"USDK if you want to convert from $ to DKK," + "\n"
"EUUS if you want to convert from ? to $," + "\n"\
"and USEU if you want to convert from $ to ?")


Thank you Jeff, that's classy! Also the exit function! Your hack will
keep me busy for at least one hour and a half (hence the mentioned
baby steps)

Allow me a remark though:

was the following output intended?

"Please enter conversion type or 'Exit': euus
Please type the amount you wish to convert: 99
? to $ 99 = 117.81"

I mean the last line. Or am I missing something?
Thanx!
Jul 18 '05 #6
>> import string

currency = {"EUDK":(7.47," ? to DKK"),
"DKEU":(0.13,"D KK to ?"),
"USDK":(5.9 3, "$ to DKK"),
"DKUS":(0.1 6, "DKK to $"),
"EUUS":(1.1 9, "? to $"),
"USEU":(0.8 4, "$ to ?")}

while(1):
currency_choice = raw_input("\nPl ease enter conversion type or
'Exit':
")
currency_str= str(currency_ch oice).upper()

if currency_str == "EXIT":
break
if currency.has_ke y(currency_str) :
amount_int= input("Please type the amount you wish to convert: ")
result = amount_int * currency[currency_str][0]
print currency[currency_str][1], " ", amount_int, " = ", result
else:
print("Sorry. At the moment we only support DKK, Euro and
Dollars."
+ "\n" \
"Type DKEU if you want convert from DKK to ?," + "\n" \
"EUDK if you want to convert from DKK to ?," + "\n" \
"DKUS if you want to convert from DKK to $," + "\n" \
"USDK if you want to convert from $ to DKK," + "\n"
"EUUS if you want to convert from ? to $," + "\n"\
"and USEU if you want to convert from $ to ?")

was the following output intended?

"Please enter conversion type or 'Exit': euus
Please type the amount you wish to convert: 99
? to $ 99 = 117.81"

I mean the last line. Or am I missing something?
Thanx!


Yes the last line was meant to show the conversion type, just a simple
remider for myself what I converted (in this case EU - designated ? - to US
dollars - designated $)
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2721
by: C. Alexander | last post by:
I'm making a 'whiteboard' application. I'm trying to have 2+ connected users able to draw at the same time. However, if User1 draws a line, when User2 is drawing, on User1 screen, it will draw another line, connecting User1's, and User2's current X,Y position. Same thing happens with User2. But User3, and User4 is not drawing, and see the lines drawn individually.
1
6560
by: Dennis | last post by:
I started a new thread because i cant reply on the older one. Thank you very much Rick for the usefull reply. But i'v got another question. When drawing the line, you cant see the line untill you release the mouse button. I want to see the line when im drawing!! Im using the following code: Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x1 = z.X
44
4705
by: Carlos Andr?s | last post by:
Hi everybody. I've got a problem. I'd like to avoid opening a new window when you have pressed the shift key and you click in the left button of the mouse. I've tried the next solution, in the body of the page I put the next code: <BODY onkeydown='notOpenNewWindow();'>
8
3209
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of working Python scripts to paste into my interactive console and let those run so I don't have to copy line-by-line. Not sure if iPython would meet that criteria or not or even if such a beast exists. It would be helpful for debugging some of my...
3
4891
by: Joshua Ammann | last post by:
I've searched for this and haven't found the answer yet, so here goes. I'm using multiple versions of Access, all 2000 or later. Is there a command line switch that will produce the same result as opening the file in Windows while holding down the bypass (shift) key? I have GoToMyPC set up on a client's computer, and when accessing it through my Pocket PC I am unable to transmit the holding of the shift key while opening the database. If...
3
3520
by: Ken Varn | last post by:
I am seeing a discrepancy on how bit shifts work in C# vs. C++. In C++, if you do a bit shift and it overflows, the bits are lost. i.e. in C++, -1 << 32 would produce 0. However, in C#, this same expression yields -1. Is there anyway to have C# bit shift behave like C++?
0
1613
by: U S Contractors Offering Service A Non-profit | last post by:
Baby steps to the "New" New Orleans Inbox Reply Craig Somerford to Chasing, Donald, me, (bcc:Discovery), (bcc:Beijing) show details 3:55 pm (0 minutes ago) Our Beloved New Orleans needs you James Taylor "CLICK" to see why Inbox Reply Craig Somerford
7
5861
by: Joy M | last post by:
Hello, I am modifying an .asp file and I noticed that the top line on the screen is blank. I would like to remove this line, and push everything up to the top of the screen, but I don't know what is causing it to appear. Does any one have any ideas of what to look for? The code has <table><tr><tdtags. There are no <formand no <p>. I hope I have given you enough information, and thank you for your help.
7
3212
by: APEJMAN | last post by:
Hi First of all I should say, I dont want to bother any one with my question or long program please if you have time, help me.( I dont mean that I want any one to do my program, just please if you are an expert and professional in C++, please help me and guid me how to fix the program) I did my best to comment my program. I am learning C++ and now I'm working on a program that: reads in a file "customers.txt" containing the information...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.