Login
Order Now
Support
Python Assignment Solution on Game of Chance

Python Assignment Solution on Game of Chance

  • 18th Aug, 2022
  • 16:39 PM

import random

from pip._vendor.pyparsing import unicode_set

print("Author: Danielle")
userName = input("Please, enter your name ")
print("Nice to meet you", userName)

rollAgain = "yes"  # variable to store the user input whether he will continue or not
while rollAgain == "yes" or rollAgain == "y":  # if the user want to play again
    computerScore = 0  # variable to score computer score
    userScore = 0  # variable to score user score
    winnerScore = 10  # the first one to score 10 points will win the
    while True:
        print("Rolling the dice ")
        computerNumber = random.randint(1, 6)  # creating computer number using random function
        userNumber = 0
        while True:
            userNumber = int(input("Enter number between 1 and 6 "))  # taking userNumber input from user
            if (userNumber > 0) and (userNumber < 7>                 break
            else:
                print("Wrong input by user")  # if the user entered wrong number than prompt message to user

        if userNumber > computerNumber:  # if userNumber is greater than computerNumber
            userScore = userScore + 1  # increase the userScore by 1
            print("User gets 1 point")
        elif computerNumber > userNumber:  # if computerNumber is greater than userNumber
            computerScore = computerScore + 1  # increase the computerScore by 1
            print("Computer gets 1 point")

        if userScore >= winnerScore or computerScore >= winnerScore:  # checking if user has win or the computer
            break
    if userScore == winnerScore:  # if the user wins
        print("User win ", userName)
    else:  # if the computer wins
        print("Computer Wins")
    roll_again = input("To play game again press enter yes or y")  # asking user if he wants to play again
 

 

Get best Python Assignment Help online on our website

Share this post

assignment helpassignment helperassignment expertsassignment writing services