Quote:
Originally Posted by TobiSGD
In python code-indentation is essential. If you don't put your scripts into code-tags no one here can see the indentation and it is impossible to help you with your problems, especially if you get IndentationErrors.
|
Using the python editor 'Kate' and the script is as follows:
# Conditional example 4 - if / elif / else
""" Note - you should be careful of the order in
which you write your conditions so that you don't
end up masking one condition behind another (this
comment applies to all languages - not just Python)"""
faren = input("Enter a temperature"\) * 9.0 / 5 + 32
print "That degrees converts to",faren
if faren > 212:
print "Steam"
elif faren > 112:
print "Very Hot Water"
elif faren > 32:
print "Water"
else:
print "Ice"
print "Program completed"
""" Sample results:
-bash-3.2$ python if4.py
Enter a temperature 33
That degrees converts to 91.4
Water
Program completed
-bash-3.2$ python if4.py
Enter a temperature -5
That degrees converts to 23.0
Ice
Program completed
-bash-3.2$
Next script:
#!/usr/bin/env python
# All comments start with a the character "#"
# This program converts human years to dog years
# get the original age
age = input("Enter your age (in human years): ")
print # print a blank line
# check if the age is valid using a simple if statement
if age < 0:
print "A negative age is not possible."
elif: age < 3 or age > 110:
print "Frankly, I don't believe you."
else:
print "That's the same as a", age/7, "year old dog."
The indentations refer to which part of the scripts?/ What should be added to them?