import os
happy = "sit"
while happy == "sit":
os.sys('clear')
F = input("F: ")
C = (F - 32) * 5 / 9
print ("C:", C)
Can someone tell me what I'm doing wrong?
Started by ki4jgt, Dec 15 2010 03:03 PM
4 replies to this topic
#1
Posted 15 December 2010 - 03:03 PM
|
|
|
#2
Posted 15 December 2010 - 03:15 PM
import os
happy = "sit"
while happy == "sit":
os.system('clear')
F = input("F: ")
CEL = (F - 32) * 5 / 9
print ("C:", CEL)
I just rewrote this, It's now giving me a F: prompt but then
I'm using 3.1 in Ubuntu
Quote
F: 6 #what I entered at the F:
Traceback (most recent call last):
File "/home/jesse/Desktop/test.py", line 6, in <module>
CEL = (F - 32) * 5 / 9
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>>
Traceback (most recent call last):
File "/home/jesse/Desktop/test.py", line 6, in <module>
CEL = (F - 32) * 5 / 9
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>>
#3
Posted 15 December 2010 - 04:31 PM
You're trying to subtract an integer from a string. You need to convert the input to an integer.
F = int(input("F: "))
#4
Posted 15 December 2010 - 04:44 PM
I ran a debuger and F is getting the equation correct. The thing is this script runs in 2.6, but not in 3.1 in 3.1 it always get hung on the last " oh and I can't import os os.sys('cls') on 2.1 so yeah, it's really messed up!
#5
Posted 15 December 2010 - 04:59 PM
It gets hung on which "?
I ran this code on ideone's python 3 (with some modification) and it worked.
I ran this code on ideone's python 3 (with some modification) and it worked.
import os
import sys
happy = "sit"
while happy == "sit":
os.system('clear')
try:
F = int(input("F: "))
except KeyboardInterrupt:
print ("Goodbye!")
sys.exit()
except:
F = 0
CEL = (F - 32) * 5 / 9
print ("C:", CEL)


Sign In
Create Account


Back to top









