Fork me on GitHub

Sierra's Python Basics

by Sierra Moore

27 Jan 2014

Here are Sierra's python exercises.

(1) This is a program for taking the sentence "All work and no play makes Jack a dull boy" and storing each word in a separate variable, then printing out the sentence on one line using print.:

a = "All"
b = "work"
c = "and"
d = "no"
e = "play"
f = "makes"
g = "Jack"
h = "a"
i = "very"
j = "dull"
k = "boy."

print a, b, c, d, e, f, g, h, i, j, k

Here is a sample input displaying a very wise adage: Jack

(2) Below is a program that will compute mpg for a car(useful!): ```

Get the number of mpg for a car

miles_driven = int(raw_input ("How many miles have been driven?"))

gallons_used = int(raw_input ("How many gallons have been used?"))

mpg= (miles_driven % gallons_used)

print "The mpg of your car is:", mpg

Here is a sample input from the mpg program:
![mpg](http://farm4.staticflickr.com/3759/12091836965_34487c3aa0_b.jpg)

<b>(3) This a program that will convert a user-input number of degrees celsius to degrees farenheit(amazing!):</b>

Convert celsius to farenheit

celsius_temp=int(raw_input("What is the celsious temperature?"))

farenheit_temp=int(celsius_temp * 5/9 + 32)

print "The temperature in farenheit is:", farenheit_temp, "F" ``` Here is a sample input from the farenheit program: to_far

(4) Here is a program that will convert a user-input number of degrees degrees farenheit to degrees celsius(stupendous): ```

Convert farenheit to celsius

farenheit_temp = int(raw_input("What is the farenheit temperature?"))

celsius_temp = int((farenheit_temp -32) * 5/9)

print "The temperature in celsius is:", celsius_temp, "C" ``` Here is a sample input from the celsius program: to_cel

(5) Here is a program that will convert degrees or celsius as above, depending on the users' choice(astonishing!):

convert_temp = int(raw_input(" Give a temperature input?"))

# Convert to farenheit or celsius
inputed_temp = raw_input("Do you want to convert to farenheit or celsius?")
if (inputed_temp) == "farenheit":
    celsius_temp = int(convert_temp-32) * 5/9
    print "The temperature conversion is:", celsius_temp, "C"
if (inputed_temp)== "celsius":
    farenheit_temp = int(convert_temp * 5/9 + 32)
    print "The temperature conversion is", farenheit_temp, "F"

Here is a sample input from the temperature conversion program: conversion

the_bitter_end

Sierra is a first year MSIS student Find Sierra Moore on Twitter, Github, and on the web.
comments powered by Disqus