Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created July 3, 2011 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zolomon/1062162 to your computer and use it in GitHub Desktop.
Save Zolomon/1062162 to your computer and use it in GitHub Desktop.
Python exercises Chapter 2
#!/usr/local/bin/python3.2
#Exercise 2.2
name = input("Write your name: ")
print("Hello", name, "!")
#!/usr/local/bin/python3.2
#Exercise 2.3
hours = int(input("Enter Hours: "))
rate = float(input("Enter Rate: "))
salary = hours * rate
print("Pay: {0:.2f}".format(salary))
#!/usr/local/bin/python3.2
#Exercise 2.4
width = 17
height = 12.0
print(width/2)
print(type(width/2))
print(width/2.0)
print(type(width/2.0))
print(height/3)
print(type(height/3))
print(1+2*5)
print(type(1+2*5))
#!/usr/local/bin/python3.2
#Exercise 2.5
from fractions import Fraction
celsius = float(input("Enter degrees in Celsius: "))
fahrenheit = celsius * Fraction(9, 5) + 32
print("{0:.2f} C⁰ is {1:.2f} F⁰".format(celsius, fahrenheit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment