Lab #3

Description: Using python script mode to create a sequence of commands and after running the script, it should ask for two integers then execute the sequence of commands which follow it.  This was similar to the second lab but I learned a better way of executing the program.  Keeping it organized helped so much.

Code: Creating a follow up sequence for the user using run on python IDLE

 

def add(x, y):
sum = x + y
print(‘sum’)
return sum

def subtract(x, y):
difference = x – y
print(‘difference’)
return difference

def product(x, y):
multiply = x * y
print(‘multiply’)
return multiply

def division(x, y):
divide = x / y
print(‘divide’)
return divide

def whatisleft(x, y):
remainder = x % y
print(‘remainder’)
return remainder

def comparison(x, y):
if (x < y):
print(x, ‘is less than’, y)
elif (x > y):
print(x, ‘is greater than’, y)
else:
print(x, ‘is equal to’, y)

while True:
print(x)
y = (x + 3/x) / 2
if y == x:
break
x = y

x = int(input(“enter a value: “))
y = int(input(“enter a value: “))
print(add(x, y))
print(subtract(x, y))
print(product(x, y))
print(division(x, y))
print(whatisleft(x, y))
print(comparison(x, y))

import sys

sys.exit(0)

Screenshots:Lab #3 screenshot part 1  Lab #3 screenshot part 2         after running it on IDLE >>>>Lab #3 screenshot after running it

Leave a Reply

Your email address will not be published. Required fields are marked *