Home » Python Programming (Page 2)

Category Archives: Python Programming

Python Programming – Week 7 Assignments

Python Programming Online Class

assignment

Week 7 Objectives
• Overview of The While Loop and Truth Table Link found here

Assignment:

Python Programming – Truth and While Loops


 

Below is an example of a While Loop, where it is checking if the condition is met. If not, The count logic will increment up to 10, before breaking out of the loop.

This provides two possible methods to break out of the loop. There are times, when a loop is infinite.While you generally do not wish to have an infinite loop, there are times you purposely create one.

One example an infinite loop is needed may be an anti-virus software, that is monitoring the registration, files, for viruses. These are always running on your computer.

 

while_loop_ex

 

 

The Truth Terms
In Python we have the following terms (characters and phrases) for determining if something is “True” or “False.” Logic on a computer is all about seeing if some combination of these characters and some variables is True at that point in the program. These are used in our conditions, such as the use of != (not equal) in our While Loop example.

and
or
not
!= (not equal)
== (equal)
>= (greater-than-equal)
<= (less-than-equal)
True
False

 

Python Programming – PyCharm Application

 

A free IDE (Integrated Development Environment)

The link for this free application is below:

https://www.jetbrains.com/pycharm/download/

Be sure to choose the Community version (Free without the need for registration, ECT.)

pycharm

Python Programming – Week 6 Assignments

Python Programming Online Class

assignment

Week 6 Objectives
• Overview of Mathematical Operators Link found here

Assignment:

Week 6 – Python Programming – Quiz

Please enter your email:

1. It is good practice to include

 
 
 
 

2. the int identifies what in Python programming?

 
 
 

3. The correct formula for Fahrenheit to Celsius is:

 
 
 

4. What is the answer if this code is ran?

 

a = 347 / 12 * 2

print (a)

 
 
 

5. If I said it was 100 degrees outside with the following program, what is my answer?

# Finds temp with Fahrenheit to Celsius formula
# Matt Cole
# 9.18.16

a = int(input(“How cold is it outside “))

celsius = (a – 32) * (5/9)

print (“It is the following “)
print (a, “in Fahrenheit and “)
print (celsius, “in Celsius.”)

 
 
 

Python Programming – Week 6 – Mathematic Operators

We have already been introduced to the input and print functions in Python, as well as the concept of the variable. Below is a simple greeter program. Notice I have included comments with the # sign. It is good practice to identify the program, and provide me a description, your name, and the date you created the program.

# Greeter Program
# Demonstrates print and input functions
# Matt Cole
# 9.18.16

name = “Matt”
print (name)
print (“Hi ” , name)

input(“\n\nPress the key to exit.”)

The above code would produce the following:

greeter

While nice, we would also like to add some additional math in our program. The video below covers some mathematical operators and expands on the greeter program, into an age difference program.

 

Here is an example for the formula Fahrenheit to Celsius.

# Demonstrates Fahrenheit to Celsius formula
# Matt Cole
# 9.18.16

F = 98.6
answer = (F – 32) * (5/9)

print (answer)

When ran, we get the answer 37.0.

 

 

 

 

Week 5 – Python Programming – Quiz

Please go to Week 5 – Python Programming – Quiz to view the test

Python Programming – Week 5 Assignments

Python Programming Online Class

assignment

Week 5 Objectives
•Overview of Lists Link found here

Assignment:
• Review and play with some lists with Python
• Create a small program similar to the Hero Inventory example and email me the program. Don’t forget your comments for your name and date.

Quiz:
Week 5 Quiz

Python Programming – Week 5 – Lists / Hero Inventory

 

Notes:

  • List can be defined as a container that holds a number of other objects, in a given order. The list type implements the sequence protocol, and also allows you to add and remove objects from the sequence.
  • Lists use square brackets as containers.
    • Example:  x = [23,24,25]
    • Example:  x = [“clinton”,”bush”,”obama”]
  • When using Strings in list, use the single or double quotes.
  • Functionalities used in a list with examples, where x is the variable.
    • append – To add a value to a list permanently.
      • Example:  x.append = ()
    • sort – To sort a list alphabetically or numerically.
      • Example: x.sort = ()
    • insert – To place a value in the list into a specific location.
      • Example: x.insert = (2,99)  where 2 is the location, and 99 is the value.
    • remove – To remove a specific value from the list.
      • Example: x.remove = ()

 

 

Above is an example of using list in the Hero inventory.

PYTHON PROGRAMMING – WEEK 4 – ASSIGNMENT(S)

Python Programming Online Class

assignment

Week 4 Objectives
•Overview of Strings Link found here
•Overview of String Slicing-Dicing Link found here

Assignment:
• Provide me the following paragraph from the given value and email me your saved program.

Given Value: D = “09052016154523”

I am requesting you to slice out the information above to create the following paragraph. Try to use the  escape character for newline.

The day value is 09. The month value is 05.
The year value is 2016.The time is 15:45.
The second value is 23.

I will get you started.

# Week 4 Assignment
# Matt Cole
# Slicing Strings

D = “09052016154523”

print (“The day value is ” + D[0:2] + “. \n” +”The month”)

Quiz:
Week 4 Quiz