473,699 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conversion code not working properly

Why is the Farenheit to Celsius part not working properly? Instead of
showing a similar range of what the farenheit is listing, the celsius
portion is showing half the range of farenheit.

print "\nWelcome to the Temperature program"

while True:
low1 = raw_input("Plea se enter a low temperature: ").upper()
if low1 != 'I QUIT':
low = int(low1)
if low1 == 'I QUIT':
break
high = int(raw_input(" Please enter a high temperature: "))
temp = raw_input('Plea se indicate Celsius or Fahrenheit ').upper()

while not temp or temp not in 'CF':
temp = raw_input('Plea se indicate Celsius or Fahrenheit
').upper()

if temp == 'C' and low <= high:

low_other_temp = (9 / 5 * low) + 32
high_other_temp = (9 / 5 * high) + 32
rnge = range(low, high + 1)
faren = range(low_other _temp, high_other_temp + 1)
print rnge
print faren

elif temp == 'F' and low <= high:

num1 = low - 32
num2 = high - 32
low_temp = num1 * 5/9
high_temp = num2 * 5/9
rnge = range(low, high + 1)
celsi = range(low_temp, high_temp + 1)
print rnge
print celsi

else:
print 'Invalid temperatures specified! The low must be less
than the high!'

exit = raw_input('Hit <enter> to continue. Type " I quit" in the
low temp field to exit.')
print 'Returning to main.'
Jul 18 '05 #1
8 1999
weasel wrote on Sun, 22 Feb 2004 19:07:01 GMT:
Why is the Farenheit to Celsius part not working properly? Instead of
showing a similar range of what the farenheit is listing, the celsius
portion is showing half the range of farenheit.
Try this in your interactive interpreter:
9/5
What's odd about the result? "/" does integer division. It's weird and
unexpected to lots of people, but it's the way it is - it will be fixed in
due time. However, due to some time machine Guido is said to possess, you
can already use the future behavior by doing this:

from __future__ import division

Then try 9/5 again. Integer division is "//" now, while "/" behaves as
floating-point division.

Alternatively, you could use a floating-point number instead of integers.
Try this in a clean interpreter session (without the from __future__
thing):
9.0/5
9/5.0
9.0/5.0


<snip> low_other_temp = (9 / 5 * low) + 32
high_other_temp = (9 / 5 * high) + 32
rnge = range(low, high + 1)
faren = range(low_other _temp, high_other_temp + 1)
print rnge
print faren

elif temp == 'F' and low <= high:

num1 = low - 32
num2 = high - 32
low_temp = num1 * 5/9
high_temp = num2 * 5/9
rnge = range(low, high + 1)
celsi = range(low_temp, high_temp + 1)
print rnge
print celsi

<snip>

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
ce******@jnanqb b.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #2
It's not working. I don't think the conversion is the problem. After
converting, the program shows the original entry you put in

i.e. Please enter low temp:
32
Please enter high temp:
42
Please enter a conversion letter (C, F):
F

Then, the display shows
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42

However,

the conversion is only showing
0, 1, 2, 3, 4, 5.

What happened to the other half? I tried using 5.0/9.0, but got the
same results.

Any more ideas?
On Sun, 22 Feb 2004 20:32:50 +0100, Andrei <fa**@fake.ne t> wrote:
weasel wrote on Sun, 22 Feb 2004 19:07:01 GMT:
Why is the Farenheit to Celsius part not working properly? Instead of
showing a similar range of what the farenheit is listing, the celsius
portion is showing half the range of farenheit.


Try this in your interactive interpreter:
9/5
What's odd about the result? "/" does integer division. It's weird and
unexpected to lots of people, but it's the way it is - it will be fixed in
due time. However, due to some time machine Guido is said to possess, you
can already use the future behavior by doing this:

from __future__ import division

Then try 9/5 again. Integer division is "//" now, while "/" behaves as
floating-point division.

Alternativel y, you could use a floating-point number instead of integers.
Try this in a clean interpreter session (without the from __future__
thing):
9.0/5
9/5.0
9.0/5.0


<snip>
low_other_temp = (9 / 5 * low) + 32
high_other_temp = (9 / 5 * high) + 32
rnge = range(low, high + 1)
faren = range(low_other _temp, high_other_temp + 1)
print rnge
print faren

elif temp == 'F' and low <= high:

num1 = low - 32
num2 = high - 32
low_temp = num1 * 5/9
high_temp = num2 * 5/9
rnge = range(low, high + 1)
celsi = range(low_temp, high_temp + 1)
print rnge
print celsi

<snip>


Jul 18 '05 #3

"weasel" <he******@hotma il.com> wrote in message
news:3u******** *************** *********@4ax.c om...
Why is the Farenheit to Celsius part not working properly?
Specific examples of what you put in, what you get out, and what you
expected out and why often helps get answers.
Instead of
showing a similar range of what the farenheit is listing, the celsius
portion is showing half the range of farenheit.


Celcius ranges are 5/9ths, approximately 1/2, the corresponding Farenheit
ranges.

Terry J. Reedy


Jul 18 '05 #4
see my other post. I've got an example of what's going wrong.

On Sun, 22 Feb 2004 14:27:28 -0500, "Terry Reedy" <tj*****@udel.e du>
wrote:

"weasel" <he******@hotma il.com> wrote in message
news:3u******* *************** **********@4ax. com...
Why is the Farenheit to Celsius part not working properly?


Specific examples of what you put in, what you get out, and what you
expected out and why often helps get answers.
Instead of
showing a similar range of what the farenheit is listing, the celsius
portion is showing half the range of farenheit.


Celcius ranges are 5/9ths, approximately 1/2, the corresponding Farenheit
ranges.

Terry J. Reedy


Jul 18 '05 #5
I just figured it out. It has to do with range. The conversion is
working, but the range functionality is screwing it all up. Back to
the drawing board!
Jul 18 '05 #6
weasel wrote on Sun, 22 Feb 2004 19:45:30 GMT:
It's not working. I don't think the conversion is the problem. After
converting, the program shows the original entry you put in
You're right, I saw integer division where you were trying to convert
temperatures and automatically assumed that was the only problem, without
really reading the code.
What happened to the other half? I tried using 5.0/9.0, but got the
same results.
How did you get range() to work on floats without deprecation warnings?
Any more ideas?


Terry Reedy answered a short while ago to why a Celsius range is by
definition shorter than a Fahrenheit range. I'm not quite sure what the
point of the conversion is to be honest, more specifically why a range is
returned. You can't map a celsius temperature in the Celsius range to a
Fahrenheid temperature in the other range and the extreme values are
incorrect due to the integer division and/or the range() used with float
arguments. 42 F should be 5.556 C and your program returns 5.

Btw, there's also a Python list for beginners if you're interested
(python-tutor).

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
ce******@jnanqb b.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #7
Well, I know that the range command is the problem, because it just
keeps adding 1 which throws off the decimal entries. So, in removing
range, I need to take the beginning temp, and add up to the ending
temp.

The conversion seems to be working fine, even by using "float" for the
input.

On Sun, 22 Feb 2004 21:15:30 +0100, Andrei <fa**@fake.ne t> wrote:
weasel wrote on Sun, 22 Feb 2004 19:45:30 GMT:
It's not working. I don't think the conversion is the problem. After
converting, the program shows the original entry you put in


You're right, I saw integer division where you were trying to convert
temperatures and automatically assumed that was the only problem, without
really reading the code.
What happened to the other half? I tried using 5.0/9.0, but got the
same results.


How did you get range() to work on floats without deprecation warnings?
Any more ideas?


Terry Reedy answered a short while ago to why a Celsius range is by
definition shorter than a Fahrenheit range. I'm not quite sure what the
point of the conversion is to be honest, more specifically why a range is
returned. You can't map a celsius temperature in the Celsius range to a
Fahrenheid temperature in the other range and the extreme values are
incorrect due to the integer division and/or the range() used with float
arguments. 42 F should be 5.556 C and your program returns 5.

Btw, there's also a Python list for beginners if you're interested
(python-tutor).


Jul 18 '05 #8
On Sun, 22 Feb 2004 20:09:17 GMT, weasel <he******@hotma il.com> wrote:
I just figured it out. It has to do with range. The conversion is
working, but the range functionality is screwing it all up. Back to
the drawing board!

Just finished it. Thank you for the suggestions, it helped me move in
the right direction.
Jul 18 '05 #9

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

Similar topics

8
3795
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i got to write them in a bmp file (in which RGB values are limited to 8 bits per channel). so i need to have them scaled down. first of all i find the highest and lowest of those values:(keep in mind that max, min, bmp, ptr are ulong and w, h are...
5
2416
by: Philip Pemberton | last post by:
Hi, I've just been trying to get some (pretty badly written) code working on a different compiler. Unfortunately, I've hit a problem. When the code below is compiled under Borland C++ it (allegedly) works fine. If I try and compile it with GNU G++, I get the following error report: bug.cpp: In function `GF2Poly operator%(OddGF2Poly&, OddGF2Poly&)': bug.cpp:21: call of overloaded `GF2Poly(OddGF2Poly&)' is ambiguous bug.cpp:3: candidates...
1
3296
by: Joe HM | last post by:
Hello - I have two Enums for which I would like to define type conversions ... Public Enum eA A2 = 0 A2 = 1 End Enum Public Enum eB B1 = 2
0
1959
by: vasudevram | last post by:
Hi group, xtopdf: PDF creation / conversion toolkit: alpha release of v1.3 This is actually a somewhat preliminary announcement, but may be of interest to developers / users who know Python and/or have earlier checked out my xtopdf PDF creation / conversion toolkit:
2
22603
by: venu reddy | last post by:
Hi all, I wrote an example code like this. I am getting error as " conversion to non-scalar type requested error". help me!!. #include<string.h> typedef struct { int val; char data;
13
3021
by: junky_fellow | last post by:
guys, I have a question regarding pointer conversion. Please look at the following code snippet. char *cptr; int *iptr; /* Some code here that initializes "iptr" */
0
27250
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications are constrained by the technology available at the time of their development and hence arenít optimum as per current scenario. One of such cases is the extensive usage of CHAR fields, which arenít optimum solution for space storage now. This paper...
9
26344
by: Eric | last post by:
I am working on a large, old code base and attempting to move it to GCC 4.2. Throughout the code, there is stuff like: char *aVar = "aString"; or void aFunc( char *aVar) { ... } aFunc( "aString" );
3
3304
by: cmrhema | last post by:
I am converting an html into pdf, I have observed that the pdf is getting generated but not properly. i.e. the Datalist2 and the gridview2 present inside the Datalist2 is not getting populated. Any idea why is it working so. I have the html code as below <table id="tblReport" runat="server"> <asp:DataList ID="DataList1" runat="server">
0
8618
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,...
0
9178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8885
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
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
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
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
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.