I’m just playing around with Python, very basic stuff.
The logic is as follows:
- User provides 3 Celsius temperatures,
- The body of the module count theirs Fahrenheit equivalents,
- And prints them out as output.
I want to use the for loop for this task.
def main():
c1, c2, c3 = input("Provide 3 Celsius temps. separated with a comma: ")
for i in range(c1, c2, c3):
fahrenheit = (9.0 / 5.0) * i + 32
print "The temperature is", fahrenheit, "degrees Fahrenheit."
main()
Well, the above code only transtaltes and prints the first Fahrenheit tempatarute that user has provided.
Some hints needed please.
Remove the
range()call altogether:Now you are making
(c1, c2, c3)a tuple, and you can loop over that directly.range()is only needed when you need to make a series of integers.When
printis given an expression with a trailing comma, it won’t print a newline, so to get all three values on one line, one (simple) way to do that would be:We can make this complicated fast, work through your tutorials a bit more and more powerful Python structures will be available soon enough. 🙂