Jump to content

Can someone tell me what I'm doing wrong?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
ki4jgt

ki4jgt

    Learning Programmer

  • Members
  • PipPipPip
  • 84 posts

import os

happy = "sit"

while happy == "sit":

    os.sys('clear')

    F = input("F: ")

    C = (F - 32) * 5 / 9

    print ("C:", C)



#2
ki4jgt

ki4jgt

    Learning Programmer

  • Members
  • PipPipPip
  • 84 posts

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'
>>>


#3
Arctic Fire

Arctic Fire

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
You're trying to subtract an integer from a string. You need to convert the input to an integer.

F = int(input("F: "))


#4
ki4jgt

ki4jgt

    Learning Programmer

  • Members
  • PipPipPip
  • 84 posts
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
Arctic Fire

Arctic Fire

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
It gets hung on which "?

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)