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("Please 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('Please indicate Celsius or Fahrenheit ').upper()
while not temp or temp not in 'CF':
temp = raw_input('Please 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.' 8 1965
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******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
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.net> 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.
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>
"weasel" <he******@hotmail.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
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.edu>
wrote: "weasel" <he******@hotmail.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
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!
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******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
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.net> 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).
On Sun, 22 Feb 2004 20:09:17 GMT, weasel <he******@hotmail.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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;
|
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" */
|
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...
|
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(...
|
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....
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |