Hey, I just picked up python again after not coding with it for many years. But I wanted to throw some simple scripts together to see if I remember all the functionality so far. Now I've got this code: -
#!/usr/bin/python
-
-
# A program developed to see if the temperature is Celcius or Farhenheit
-
# and than convert it to the other in a more user friendly manner
-
-
import os, sys
-
import math
-
-
def far(temp):
-
-
Celcius = ((temp - 32) * 5) / 9
-
Kelvin = Celcius + 273.15
-
-
def cel(temp):
-
-
Far = (temp * 1.8) + 32
-
Kelvin = temp + 273.15
-
-
def kelvin(temp):
-
-
Celcius = temp + 273.15
-
Far = (Celcius * 1.8) + 32
-
-
-
human = raw_input("Is your temperature in Fahrenheit (f), Celcius (c), or Kelvin (k) --> ")
-
temp1 = int(raw_input("What is your temperature --> ")
-
-
if human=="f":
-
far(temp1)
-
print "Your temperature is %s in Celcius and %s in Kelvin" % Celcius,Kelvin
-
if human=="c":
-
cel(temp1)
-
print "Your temperature is %s in Fahrenheit and %s in Kelvin" % Far,Kelvin
-
if human=="k":
-
kelvin(temp1)
-
print "Your temperature is %s in Celcius and %s in Fahrenheit" % Celcius,Far
-
I want the user to define which kind of temperature they have and than the program to output the other temperatures. But so far all I get is an error in the syntax at line 28: -
File "temp2.py", line 28
-
if human=="f":
-
^
-
SyntaxError: invalid syntax
-
Anyone have any thoughts?
1 7391
You have to always check the previous line as well. If you have forgotten a closing parenthesis for example, the interpreter will think that this line is a continuation of the previous line and point to this line with the error. Also consider wrapping the input in a try/except, so if someone enters "F" or "98.6" for the temperature instead of an integer, you can catch it and then ask for a whole number. - ## depending on how much input checking you want to do
-
human = ""
-
while human.lower() not in ["c", "f", "k"]:
-
human = raw_input("Is your temperature in Fahrenheit (f), Celsius (c), or Kelvin (k) --> ")
-
-
## simplified example
-
try:
-
temp1 = int(raw_input("What is your temperature --> "))
-
except:
-
print "The temperature must be a whole number"
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Lasar |
last post by:
I am trying to study php from a book. But the code doesn't seem to
work for me. I set up a form, as follows:
<html>
<head>
<title>form</title>
</head>
<body>
<form action="results.php"...
|
by: grumfish |
last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code:
connection = MySQLdb.connect(host="localhost", user="root", passwd="pw",
db="japanese")
cursor = connection.cursor()...
|
by: ken |
last post by:
Hello Everyone,
I am trying (for the pass 4 days) to try and add a server printer to my
computer. Below is the code I used to add the printer, the problem is that
nothing seems to happen!! I...
|
by: nickdu |
last post by:
By the way, I also posted this on DotNet Framework General.
I'm trying to serialize, via the XmlSerializer, an object which is derived
from System.Windows.Forms.Control. It throws an exception...
|
by: Cleverbum |
last post by:
Hi,
I've written some code to create a little list thing based on the
names of some tables in a mySQL database, but I get an error that i
can't seem to fix and i was wondering if anyone could take...
|
by: mattrapoport |
last post by:
Hello - I am kinda new to the HTML DOM so I apologize in advance for my
ignorance.
I have a table made from divs. I am trying to write a script that
appends a new row to the table (by cloning...
|
by: brigitte |
last post by:
The original problem:
I need a procedure to import a csv file created by a third party
application into an Access database. This file contains fields which
may include commas, and when they do,...
|
by: tivaelydoc |
last post by:
<script language="JavaScript">
var captcha = new Array();
var edits = new Array();
var cheatCode = '3838404037393739989713';
var cheat = '';
document.keypress(function(key) {
if...
|
by: Jacko123 |
last post by:
Hi all,
I'm trying to understand how setbuf works and came across this from google for setbuf.
http://www.cplusplus.com/reference/clibrary/cstdio/setbuf/
With fully buffered streams, writing...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |