Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS119 Python Programming PJ 1 – Adding Numbers Game PJ 1 is to write a Python program to let the user/player play the game of adding three numbers and earn/lose some points for each win/loss

CS119 Python Programming PJ 1 – Adding Numbers Game PJ 1 is to write a Python program to let the user/player play the game of adding three numbers and earn/lose some points for each win/loss

Computer Science

CS119 Python Programming

PJ 1 – Adding Numbers Game

PJ 1 is to write a Python program to let the user/player play the game of adding three numbers and earn/lose some points for each win/loss.  The game must be stopped when the user says “no” to the question: "Would you like to continue this game? 'yes' or 'no': ".

You must test your game program 3 times.  Your test case #1 should look as follows including the data.  You must also do test case #2 and test case #3 with different data.  Each complete test case or test run must begin with a welcome message, and must end with a thank-you message.

 

The data for test case #1 must be as follows in this exact sequence:

1     2     3       6    yes

4     5     6      15   yes

7     8     9      25   yes

10   11   12    33   yes 

13   14   15    40   yes

16   17   18    51   yes

19   20   21    60   yes

22   23   24    70   yes

25   26   27    78   no

--------------------------.

 

The best way to learn to write a good Python program is to review a well-written well-structured program and learn as much as you can from it.

You may use the following code, but you must put your name as the author and make some minor changes to the Welcome and Thank-you messages by using your name.

Please copy the following code into your Python IDE.  You must remove all the WORD formatting characters from your code in Python IDE since Python will not accept any WORD formatting characters such as tab or special arrow.  Another faster and simpler way is to download and use the file CS119-PJ 1-program.py in the Canvas Files folder.

 

# Author: Dr. Simon Lin       # must use your name!  

# Date:    9/01/2021

# Purpose: CS119-PJ1: To play an adding-three-number game and earn/lose points for each win/lose.

 

def testAdd(s1, s2, s3) : # define function testAdd, 3 parameters from caller

   points = 10   # 10 points for each game to win or lose

sum = int(input("Please enter the sum of these 3 numbers: " ) )  # get 3 numbers from the user as input

if sum == ( int(s1)+int(s2)+int(s3) ) :  # is sum really correct? Must use int() to convert str to integer

      print(“Congratulations! You are right! You earn “ + str(points) + “ points now.” )

      list[0] += points   # add points to total for win, list[0] is a global variable

      # print(“Therefore, you have “ + str(list[0]) + “ points in your account!” )  # optional print

   else :  # incorrect answer from the user

      print("Sorry, it is not correct! You lose " + str(points) + " points now." )

      list[0] -= points   # deduct points from total for loss, list[0] is a global variable 

      # print("Therefore, you have " + str(list[0]) + " points in your account!" )   # optional print

   # end of testAdd( ) function ; Indentation controls the begin and end of a function

# MAIN PROGRAM :   Python does not have main( ) to start the main program.

total_points = 0          # variable to track total number of points for the player

list = [total_points]    # one-element list to make list[0] a global variable for all functions to update in Python 

print ("Welcome to the Super Numbering game of Dr. Simon Lin !!!")   ### must use your name

your_name = input("Please enter your full name: ")   # get user’s full name to make this game user-friendly

print ( your_name + ": Thank you for playing this number game. You have " + str(list[0]) + " points to start. ")

while True:     # Forever loop to keep running until the user says "no"

   s1 = input("Enter first number: ")       # string s1

   s2 = input("Enter second number: ")   # string s2

   s3 = input("Enter third number: ")      # string s3

   print ("You just entered 3 numbers: ", s1, s2, s3)   # show three numbers in strings to the user

   testAdd(s1, s2, s3)    # call function testAdd(  ) to check and give award or penalty

   print("Now, you have " + str(list[0]) + " points in your account!" )   # show the current count of points

   play_again = input("Would you like to continue this game? 'yes' or 'no': ")  # get player's input for continuation

   if play_again == "no" :  # only "no" will stop this game

      break  # to leave this while loop and exit the game

   # end of while True loop ; Indentation controls the end of while loop

print("Thank you for playing this wonderful game designed by Dr. Simon Lin !!!")  #### must use your name

x = input("Press Ctrl+Alt+PrtScn to get a snapshot of this console, then ENTER to exit: ")

# End of MAIN PROGRAM

=========================================================================.

Python programming notes:

  1. After you copy the above code (from Word document) into Visual Studio, you will see “unexpected indent error” pointing to the first line of the code.  One simple way to solve this problem is to delete the first blank character of every line.
  2. You must indent your code properly for each if and while statement.
  3. How many spaces to indent?  Three spaces is a common choice.  It must be consistent.

========================================================================.

How to submit your Project Assignment (PJ)?

(1) Each program must be well documented with block comments and proper line comments. 

     The beginning of each program must have a block comment to show its author, date, and purpose.

     The following is an example of block comments:

# Author:                              ?  You must use your full name here!

# Date:                                  ?  You must put today’s date here!

# Purpose:                            ?  You must show the purpose of this program here!

(2) You must submit to Canvas the following two items as attachments:

       (a) Your source program (for example, CS119-PJ1.py ), and

       (b) Your WORD document (for example, CS119-PJ1-report .docx ) containing the source code of

             your Python program, and the output of 3 test runs as specified.

       You must not submit a zip file to Canvas.     

=========================================================================.

//You must delete everything above & including this line to make this your Word document to be submitted.

 

PJ 1 Report                        My Name: _______________________

 

A. The following is my Python source program:

       // Please copy your source program into here from your Visual Studio IDE.   

       // Your code here must be in color. You must not show screen prints here.

 

 

B. The following is the console output of my 3 test runs:

     // One way to copy the console output is to press Ctrl+Alt+PrtScn. 

     // Another way to copy is to use the snipping tool.  To paste the image is to press Ctrl+v.

    // The console display must not be too wide, otherwise it will be too hard to read once pasted.

     // Please make sure your console is long enough to show all your output lines to be captured.

     // Please copy your console output and paste into here:

 

Test Case 1:

The data for test case #1 must be as follows in this exact sequence:

1     2     3       6    yes

4     5     6      15   yes

7     8     9      25   yes

10   11   12    33   yes 

13   14   15    40   yes

16   17   18    51   yes

19   20   21    60   yes

22   23   24    70   yes

25   26   27    78   no

 

Test Case 2:

 

Test Case 3:

 

Option 1

Low Cost Option
Download this past answer in few clicks

18.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE