Lab 2

This lab is about control flow and while loop statement. Throughout, this lab# 2 i learned how to make a while loop satement and sequential statement. I had little difficulties with sequential statement and while loop.

Source code: m = 1
while m==1:
x = input(‘Enter a number: ‘)
print x
m = input (‘Do you want to continue? (enter 1 is Yes)’)
if x == 2:
break

x = input (‘Enter thr first number: ‘)
y = input (‘Enter thr second number: ‘)
print ‘Enter 1 to add the numbers’
print ‘Enter 2 to subrtract the numbers’
print ‘Enter 3 to multiply the numbers’
print ‘Enter 4 to divide the numbers’
print ‘Enter 5 for remainder of the numbers’
print ‘Enter 6 is for less, equal, greater numbers’

z = input(‘Enter a selection: ‘)
if z == 1:
result = x+y
print ‘The sum of ‘,x,’ and’, y, ‘ is: ‘,result
elif z ==2:
result = x-y
print ‘The difference of ‘,x,’ and’, y, ‘ is: ‘,result
elif z == 3:
result = x*y
print ‘The product of ‘,x,’ and’, y, ‘ is: ‘,result
elif z == 4:
result = x/y
print ‘The quotient of ‘,x,’ and’, y,’ is: ‘, result
elif z == 5:
result == x%y
print ‘ The remainder of ‘,x,’and’, y,’ is: ‘, result
elif z == 6:
result = x<y
print ‘The value of ‘,x,’ and’, y,’ is: ‘, result

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.

By Dr. José M. Reyes Álamo 12:23 pm