In: Computer Science
6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic 6!” if either of the two integers is a 6 or if their sum or difference is a 6. Otherwise, the program will display “Not a magic 6.” Note, you will need to determine the larger number when calculating the difference, to get a positive difference. You cannot use any built-in Python functions to do this. Type your pseudocode into your answer document.
7- Write problem #6 as a working Python program. Include a main() module and the following calls to magicSix() to test your program. Take a screenshot of your code and output window and paste into your answer document.
magicSix(5, 5) Output: Not a magic 6.
magicSix(6, 5) Output: Magic 6!
magicSix(4, 2) Output: Magic 6!
magicSix(4, 10) Output: Magic 6!
Pseudo Code:
Input: integer1,integer2
Module magic_six()
if integer2 > integer1 then swap both integers
if integer1=6 or integer2=6 then display Magic 6!
elif (intger1+integer2)=6 or (intger1+integer2) then display Magic 6!
else display Not a magic 6.
end Module.
Python Code:
def magicSix(num1,num2):
if num2>num1: #if num2 is greater than num1 then swap the
values
num1,num2=num2,num1
if (num1==6 or num2==6): #if num1 is 6 or num2 is 6 then return
Magic 6!
return "Magic 6!"
elif (num1+num2==6 or num1-num2==6): #if sum or difference of
numbers is 6 then return Magic 6!
return "Magic 6!"
else:
return "Not a magic 6." #else return Not a magic 6.
def main():
print(magicSix(5, 5)) #calling magicSix() function
print(magicSix(6, 5))
print(magicSix(4, 2))
print(magicSix(4, 10))
main()
Code and Output Screenshots:
Note: In python indentation is important so please refer the code screenshot for correct indentation.
Note: if you have any queries please post a comment before giving any review thanks a lot..always available to help you...