Sign In
Not register? Register Now!
Essay Available:
Pages:
2 pages/≈550 words
Sources:
No Sources
Level:
APA
Subject:
Technology
Type:
Coursework
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 12.96
Topic:

Conditional Iterations and Loops (Coursework Sample)

Instructions:

Module 3 - SLP
CONDITIONAL, ITERATIONS, AND LOOPS
Use Python to run the following .py Files with the original values and statements. Next, change some of the values to the following. Please keep in mind that statements may change accordingly once you modify the programs. The modified programs must execute correctly.
Code is adapted from MITOpenCourseWare, “A gentle introduction to programming using Python” (under the Open Education Consortium Global Network for Open Education and authorized by the creative commons license).
For Example 1, change 56” to 65” and 150 to 175
For Example 2, change 9 > 5 to 5 < 9
For Example 3, change the string ‘Hello, world’ to ‘You are welcome!’ and for the while loop example, change counter from 100 to 25. You may change any the loop examples and values to an integer of your choice.
1 - Height Example .py File
# Lecture 3
#height_example.py
# Problem Statement:
# If you're taller than 56", you can ride Space Mountain at Disneyland.
# If you're shorter, you cannot.
# Additionally if you are greater than 150 inches, you are super tall and
# deserve a witty message.
# Get user's height
height = input("How tall are you? ")
# Do this if statement first
if height > 150:
print "wow you're tall!"
# Do this one second - so people who are tall get the witty message
# AND get permission to ride the ride
if height >= 56:
print "ok"
else:
print "too short"
2 - Conditional Example .py File
# Lecture 3
# conditional_examples.py
# Boolean math
# Examples of if statements
# General format:
# if <condition is True>:
# <code to execute if condition is True>
if 9 > 5:
print "Yes, 9 greater than 5"
if 9 != 5:
print "Yes, 9 not equal to 5"
# An example of an if/else statement
# General format:
# if <condition is True>:
# <code to execute if condition is True>
# else:
# <code to execute if condition is False>
#if 9 < 5:
# print "Yes, 9 less than 5"
#else:
# print "No, 9 is not less than 5"
# An example using "not" and "and" keywords
#if not (10 == 4) and 9 > 5:
# print "Yay, basic math competency achieved!"
#else:
# print ":("
# Traffic light example
#light_color = raw_input("What color is the traffic light? ")
#light_color = light_color.lower()
#print light_color
#if light_color == "red":
# print "You should stop"
#elif light_color == "yellow":
# print "Slow down!"
#elif light_color == "green":
# print "Go ahead!"
#else:
# print "What country are you in""
3 - Loop Example .py File
# Lecture 3
# loop_examples.py
# An example of a for loop
# A string
hello_world = 'hello, world!'
# Initalize a variable to hold a count of letters
letter_count = 0
# Go through all the letters in a string
for letter in hello_world: # Remember the colon!
# Print out the position of each letter
print "Letter number", letter_count, "is", letter
# And increment the counter
letter_count = letter_count + 1 # Can also do letter_count += 1
# Finally print how many letters were in the string
print "There were", letter_count, "letters in the string", hello_world
# For loop examples using range:
# Range with 1 argument goes from 0 through n-1
#for num in range(10):
# print num
# Range with 2 arguments goes from the first number through the last-1
#for num in range(7, 15):
# print num
# Range with 3 arguments goes from the first number through the
# second-1, in increments determined by the third number
#for num in range(2, 12, 2): # What happens if the 3rd number is negative?
# print num
# A while loop example
# Initialize a counter
#count = 1
#print "Count is initially", count
# Want to keep looping until the counter is bigger than 100
#while count < 100:
# count = count * 9
# print "Now count is", count
# When we get here, the while loop is done - so count must be > 100
#print "the counter is", count
Once you have executed these programs (1 - Height Example; 2 - Conditional Example; and 3- Loop Example), modify the .py files according to the instructions given to revise the code by program examples. You need to run the IDLE to execute the program changes and review the program results.
You can use the Snipping tools or screen print (ctrl + Print Screen) to show the Pythons editor’s (IDLE) code and results and demonstrate that your program executed correctly.
Create a submission file named as “ITM205-SLP3-Exercises-YourFirstNameLastName “containing executed programs (.py files) for 1 - Height Example; 2 - Conditional Example; and 3- Loop Example.
Write a summary document in Microsoft Word format named as “ITM205-SLP3-Summary-YourFirstNameLastName” to show what you have accomplished.

source..
Content:

CONDITIONAL, ITERATIONS, AND LOOPS
Name:
Institution:
Summary of what I have learnt.
Exa...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

You Might Also Like Other Topics Related to the yellow wallpaper:

  • The Yellow Wallpaper, The Rocking-Horse Winner
    Description: In The Rocking-Horse Winner, there are varieties of supernatural elements. Paul grows in a house where money is a problem for his family...
    1 page/≈275 words | No Sources | APA | Literature & Language | Coursework |
  • Introduction to Probability
    Description: Problems need to include all required steps and answers for full credit. All answers need to be reduced to lowest terms where possible....
    10 pages/≈2750 words | No Sources | APA | Mathematics & Economics | Math Problem |
  • Identity Dynamics
    Description: Even though, there are various genres of music associated with the African American culture from jazz to blues, Hip Hop is popular among the youth...
    1 page/≈275 words | No Sources | MLA | Social Sciences | Essay |
Need a Plagiarism Free Essay?
Submit your instructions!