Lab 4

Lab Description:

This example is to write a function that takes a string as an argument and displays the letters backward, one per line. The next example for excercise 3, is to write function that takes a list of numbers and returns the cumulative sum; that is, a new list where the ith element is the sum of the first i+1 elements from the original list. For example, the cumulative sum of [1, 2, 3] is [1, 3, 6].

Code:

name = input(‘enter a name: ‘) len_name = len(name) name_rev = name[len_name – 1] print(name_rev) len_name = len_name-1

while len_name != 0:     name_rev = name[len_name – 1]     print (name_rev)     len_name = len_name – 1

#Excersise 3

def add_all(t):     total = 0     for x in t:         total = total + x     return total

t = [1, 2, 4, 8, 16] sum (t)

ScreenShots:

 

 

Lab 1B

Lab Description:

This is an example of how to construct a code to find the area of a circle with a radius of 3.

Code:

import math

strRad = input (“Please input the radius of your circle => “) fltRad = float (strRad) ##print(type(strRad)

area = math.pi * fltRad ** 2 ##print(area)

print(“The area of the circle with radius “, fltRad, “is: “, area)

Radius = 3

 Screenshot:

 

 

 

 

 

 

 

 

 

 

 

 

Lab 0

This is an example how your lab reports should look like. The first item is a lab description in your own words of what the lab is about and how you did it, followed by the source code, and finally the screenshots. To correctly display the source code, make sure that when create the page, you switch to the HTML view and surround the code with the tags <pre> </pre>. The <pre> HTML tag is used for pre-formatted text, so it will respect indentation, spaces, tabs, etc. If you don’t use it the code will be hard to read. Using the <pre> HTML tag (or equivalent formatting) is mandatory.

Code:

title = 'this is a string'
index = 0
result = ''
while index < len(title):
    letter = title[index]
    result = result + letter 
    index = index + 1
print (result)

Screenshots:

This section contains screenshots showing your program running. If the image is not too big, you will be able to just copy/paste it as using a word processor. If it’s too big, then you can either reduce it’s size or upload it and the insert it into the post.