, ,

[SOLVED] Csc150 assignment 7

$25

File Name: Csc150_assignment_7.zip
File Size: 178.98 KB

5/5 - (1 vote)

Write a program that simulates a simple dice game between the computer and the user. When the program is run, it should randomly select a number between 1 and 6 for both the user and the computer. After selecting these numbers, the program should print out the numbers and determine who the winner is. The winner is the one who has the higher number. If both numbers are the same, then it is a tie.

The program should include multiple runs of the game. It should ask the user whether he/she wants to play again after each run. If the user enters ‘y’ or ‘Y’, then the game should run again. If the user enters ‘n’ or ‘N’, then the program should print out a message thanking the user for playing and then terminate. You should use a loop to implement this feature. You should also use the random number generator to generate the numbers for the dice rolls.

Sample Runs:

Let’s play a game of dice! We both roll and whoever is higher after 3 runs wins! Do you want to play? (y/n) y

Your number is: 4 Computer’s number is: 3

Computer Wins!

The score is: You: 0 Computer: 1

Do you want to play again? (y/n) y

Your number is: 2 Computer’s number is: 5

Computer Wins!

The score is: You: 0 Computer: 2

Do you want to play again? (y/n) y

Your number is: 3 Computer’s number is: 2

You Win!

The score is: You: 1 Computer: 2

Do you want to play again? (y/n) y

Your number is: 1 Computer’s number is: 2

Computer Wins!

The score is: You: 1 Computer: 3

Do you want to play again? (y/n) y

Your number is: 5 Computer’s number is: 5

It’s a tie!

The score is: You: 1 Computer: 3

Do you want to play again? (y/n) n

That was the best match! I won! Thank you for playing with me!

Notes:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Csc150 assignment 7[SOLVED] Csc150 assignment 7
$25