Question

In: Computer Science

6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic...

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!

Solutions

Expert Solution

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...


Related Solutions

Draw a flowchart and pseudocode that accepts three numbers from a user and displays a message...
Draw a flowchart and pseudocode that accepts three numbers from a user and displays a message if the sum of any two numbers equals the third. Make a working version of this program in Python.
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the...
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the integers not common to both arrays. When writing pseudocode, consider that no implementation for data structures or algorithms exist. b) Implement your algorithm in Modern C++
Write a Calculate class which contains methods that accepts two integers as arguments and return the...
Write a Calculate class which contains methods that accepts two integers as arguments and return the results of Addition, Subtraction, Division and Multiplication. Call these methods though main()and print the results.
***JAVA PROGRAM Write a method called shrink that accepts an array of integers (that the user...
***JAVA PROGRAM Write a method called shrink that accepts an array of integers (that the user inputs) as a parameter and returns a new array containing the result of replacing each pair of integers with the sum of that pair. For example, if an array called list stores the values {7, 2, 8, 9, 4, 15, 7, 1, 9, 10}, then the call of shrink(list) should return a new array containing {9, 17, 19, 8, 19}. The first pair from...
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays...
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask...
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays...
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so,” “Yes, of course!,” “I’m not sure,” and so forth. The program should read the responses from the file into an array or ArrayList object. It should prompt the...
Write a Java program that reads two integers on the keyboard and displays them on the...
Write a Java program that reads two integers on the keyboard and displays them on the screen.
The program asks user to enter three integers, and the displays a message indicating whether the...
The program asks user to enter three integers, and the displays a message indicating whether the numbers are in sequential order, in reverse order or in neither order. Find the errors and correct the program codes in the if comparison expressions. (10 points) 1.     using System; 2.     using static System.Console; 3. 4.     class Sorting 5.     { 6.              static void Main() 7.              { 8.                       int num1, num2, num3; 9.                       string snum1, snum2, snum3; 10.                    Write ("Enter first number "); 11.                    snum1...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain duplicated integers, and which outputs the input list as a sorted list in ascending order without duplication You can use either Ruby, C, C++, C# or Java to implement your program (referred to as P). 2. Design a test suite of 10 test cases (referred to as TC). Each test case has not more than 20 integers. 3. Test P against TC to make...
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT