User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 423,340 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,139 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 225 | Replies: 2
Reply
Join Date: Jun 2008
Posts: 1
Reputation: Chris9999 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chris9999 Chris9999 is offline Offline
Newbie Poster

My 10 line calculator, I want it to display decimals when the equation calls for it.

  #1  
Jun 30th, 2008
  1. Y=1
  2. N=0
  3. cont=Y
  4. print "Welcome to SCLMIP(Simple Calculator For Linux Made In Python)"
  5. while cont == Y:
  6. equation=input("Equation: ")
  7. print equation
  8. cont=input("Continue? (Y,N)")
  9. else:
  10. print "Exiting..."

If you type 5/2 you get 2, I want it to display 2.5.

A workaround is typing 5.0/2.0, but it gets annoying. I want it to automatically decide to show decimals.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 34
Reputation: AceofSpades19 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
AceofSpades19's Avatar
AceofSpades19 AceofSpades19 is offline Offline
Light Poster

Re: My 10 line calculator, I want it to display decimals when the equation calls for it.

  #2  
Jul 1st, 2008
I know this doesn't answer the question, but
Could you just use True and False keywords instead of Y and N?
Reply With Quote  
Join Date: Aug 2005
Posts: 1,115
Reputation: Ene Uran is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 66
Ene Uran's Avatar
Ene Uran Ene Uran is online now Online
Veteran Poster

Re: My 10 line calculator, I want it to display decimals when the equation calls for it.

  #3  
Jul 1st, 2008
Starting with Python3 the / will be float division and // will be integer division. You can use these future feature already by importing the __future__ module:
  1. from __future__ import division
  2. print "Welcome to SCLMIP(Simple Calculator For Linux Made In Python)"
  3. while True:
  4. equation = input("Equation: ")
  5. print equation
  6. if raw_input("Continue? (Y,N)").upper() == 'N': break
  7. else:
  8. print "Exiting..."
drink her pretty
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Python Forum

All times are GMT -4. The time now is 11:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC