
Write a python code
Step 1: Start Visual Studio Code.. Prior to entering code, save your file by clicking on File and then Save. Select your location and save this file as Lab7.py. Be sure to include the .py extension.
Step 2: Document the first few lines of your
Step 3: Start your program with the following code for main:
# Lab 7-3 The Dice Game
# add libraries needed
# the main function
def main():
print()
# initialize variables
# call to inputNames
# while loop to run program again
while endProgram == 'no':
# populate variables
# call to rollDice
# call to displayInfo
endProgram = input('Do you want to end program? (yes/no): ')
#this function gets the players names
#this function will get the random values
#this function displays the winner
# calls main
main()
Step 4: Under the comment for adding libraries, add the following statement:
import random
Step 5: Under the comment for initialize variables, set endProgram to ‘no’ and playerOne and playerTwo to ‘NO NAME’.
Step 6: Under the comment for making a call to inputNames, set the function call to both playerOne and playerTwo and pass both variables to the function as arguments. This must be done because both values need to be returned from the function. This is done as follows:
playerOne, playerTwo = inputNames(playerOne, playerTwo)
Step 7: Inside your while loop, set winnersName to ‘NO NAME’ and p1number and p2number to 0.
Step 8: Make a call to rollDice and pass the necessary variables needed in this function. This function should be set to the winnerName as that variable will be returned from the function. This is done as follows:
winnerName = rollDice(p1number, p2number, playerOne, playerTwo,
winnerName)
Step 9: Make a call to displayInfo and pass it winnerName.
Step 10: The next step is to write the function that will allow both players to enter their names. Write a function heading that matches your function call in Step 6, making sure to accept two arguments. The body of this function will use the input function to take in both players names, and one return statement that returns both playerOne and playerTwo variable The return statement should look as follows:
return playerOne, playerTwo
Step 11: The next function to code is the rollDice function. Write the function header to match the function call in Step 8. This function body will call the random function to determine p1number and p2number. The code should look as follows:
p1number = random.randint(1, 6)
p2number = random.randint(1, 6)
Step 12: Next, inside this function write a nested if else statement that will set winnerName to either playerOne, playerTwo, or "TIE".
Step 13: The final step in this function is to return winnerName.
Step 14: The final function to code is the displayInfo function. Write the function header to match the call made in Step 9. The body of the function should simply print the winnerName variable to the screen.

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Write a macro named mWriteAt that locates the cursor and writes a string literal to the consolewindow. Suggestion: Invoke the mGotoxy and mWrite macros from the book’s macro library.arrow_forwardPlease use Raptor Flowchartarrow_forwardHi, I need to solve this problem with C++ programming language using Visual Studio. Thank you.arrow_forward
- create an image file programmatically. Your image file should be called OnTheFlyPy.ppm and the code you write to create should be in a public static void makePPM() method defined in the provided Main.java class. Your OnTheFlyPy.ppm should be be 100 pixels wide and 100 pixels tall and the PPM header lines should be correct. The first two rows and last two rows in the OnTheFlyPy.ppm should be red (Red=255, Green=0, Blue= 0). The first two columns and last two columns in the OnTheFlyPy.ppm (except for the part that overlaps with the red pixels you created in the previous part) should should be blue (Red=0, Green=0, Blue= 255). The remaining pixels in your OnTheFlyPy.ppm image should be white (Red=255, Green=255, Blue= 255). Here is a picture of what your final image should look like: import java.io.*; public class Main{ public static void main(String[] args) { makePPM(); } public static void makePPM() { } }arrow_forwardCan you write the code in C++ please?arrow_forwardplease look at the screenshot instructions to help me create a flowchart of this c++ code ,also you dont need to do the other tasks just help me to create a flowchart regarding the instructions given, thank youarrow_forward
- Your application will demonstrate the use of a loop to determine the smallest value entered by the user. Incorporate the following requirements into your application: The program will consist of one file - the main application class Name the class appropriately and name the file Program.cs (the default when you create the application) Include documentation at the top of the file that includes Your name Date of development Assignment (e.g., CIS214 Performance Assessment - Smallest Number) Description of the class The main application class must meet the following requirements Print a line that states "Your Name - Week 2 PA Smallest Number" Ask the user how many integers they will enter Loop to get the specified number of integers from the user Print the value of the smallest integer entered by the userarrow_forwardCreate a folder named lastnameCh6Sum where the last name is your last name. Example: summersCh6Sum Inside your new folder place a copy of the attached numbers.txt file I have attached below. Write the following python program and save it in your new folder This program must open up the numbers.txt file, read all the numbers in the file, calculate their total, output the sum to a new file named sum.txt as well as display the sum to the screen. Make sure to display a message to the user before you print the sum to the screen that lets the user know that the sum has been calculated and saved in the sum.txt file. Also display the total on the screen.arrow_forwardThere is no end required in a flowchart? True Falsearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





