COMP 1039: Problem Solving and Programming Assessment Answers

December 14, 2018
Author : Julia Miles

Solution Code: 1ABAA

Question:

This assignment is related to ”Programming” and experts atMy Assignment Services AUsuccessfully delivered HD quality work within the given deadline.

Programming Assignment Help

The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course by applying your knowledge and skills to a simple encryption technique and the implementation of a game called Two-Dice Pig.

ASSIGNMENT OVERVIEW

There are two parts to this assignment:

Part I: Encryption

You are required to write a Python program that performs simple encryption and decryption on strings entered by the user. To do so, you are to use one of the simplest and most widely known encryption techniques known as the Caesar Cipher. The Caesar Cipher is named after Julius Caesar who used it for private correspondence.

Part II: Two-Dice Pig

You are required to write a Python program that plays a game of Two-Dice Pig with the user.

These assignments are solved by our professional programming assignment Expertsat My Assignment Services AU and the solution are high quality of work as well as 100% plagiarism free. The assignment solution was delivered within 2-3 Days.

Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.

Solution:

STEP1

from random import randint

proceed = "r"

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))

die2 = (randint(1,6))

dietotal = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal)

if proceed == "h":

print "Thanks for playing!"

 

STEP2

 

from random import randint

proceed = "r"

die_turntotal = 0

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))

die2 = (randint(1,6))

dietotal = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal)

die_turntotal = die_turntotal + dietotal

if die1 == 1 and die2 == 1:

proceed = "losetotal"

elif die1 == 1 or die2 == 1:

proceed = "loseall"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal,die_turntotal)

if proceed == "h":

print "Thanks for playing!"

elif proceed == "losetotal":

print "Thanks for playing!"

elif proceed == "loseall":

print "Thanks for playing!"

 

STEP3

 

from random import randint

proceed = "r"

die_turntotal = 0

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))

die2 = (randint(1,6))

dietotal = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal)

die_turntotal = die_turntotal + dietotal

if die1 == 1 and die2 == 1:

proceed = "losetotal"

elif die1 == 1 or die2 == 1:

proceed = "loseall"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal,die_turntotal)

if proceed == "h":

print "| *** Hold!"

print "| *** Player's score: {0} | Computer's score: 0\nThanks for playing!".format(die_turntotal)

elif proceed == "losetotal":

print "| *** You rolled two ONEs – You lose all points!\nThanks for playing!"

print "| *** Player's score: 0 | Computer's score: 0"

elif proceed == "loseall":

print "| *** You rolled a ONE - Turn over - No points for you!\nThanks for playing!"

print "| *** Player's score: 0 | Computer's score: 0"

 

STEP4

 

from random import randint

proceed = "r"

die_turntotal = 0

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))

die2 = (randint(1,6))

dietotal = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal)

die_turntotal = die_turntotal + dietotal

if die1 == 1 and die2 == 1:

proceed = "losetotal"

elif die1 == 1 or die2 == 1:

proceed = "loseall"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal,die_turntotal)

if die_turntotal >= 20:

proceed = "h"

if proceed == "h":

print "| *** Hold!"

print "| *** Computer's score: {0} | Player's score: 0".format(die_turntotal)

elif proceed == "losetotal":

print "| *** Computer rolled two ONEs - Computer lose all points!"

print "| *** Computer's score: 0 | Player's score: 0"

elif proceed == "loseall":

print "| *** Computer rolled a ONE - Turn over - No points for you!"

print "| *** Computer's score: 0 | Player's score: 0"

 

STEP5

 

while proceed == "r":

die1 = (randint(1, 6))#Random generation of numbers for die's

die2 = (randint(1, 6))

dietotal_comp = die1 + die2#Add dies in one throw

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1, die2, dietotal_comp)

die_turntotal = die_turntotal + dietotal_comp#Total tuen score

dietotal_comp = 0

comp_goaltotal = temp_total_comp + die_turntotal#Total potential score calculation

 

if die1 == 1 and die2 == 1:

proceed = "losetotal"

comp_goaltotal = 0

elif die1 == 1 or die2 == 1:

proceed = "loseall"

comp_goaltotal = comp_goaltotal - die_turntotal

else:

if die_turntotal >= 20:#Hold at 20 policy

proceed = "h"

comp_goaltotal = temp_total_comp + die_turntotal

if comp_goaltotal >= 100:#Goal policy

proceed = "win"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal, comp_goaltotal)

 

if proceed == "h":

print "| *** Hold!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "losetotal":

print "| *** Computer rolled two ONEs - Computer loses all points!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "loseall":

print "| *** Computer rolled a ONE - Turn over - No points for Computer!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "win":

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

print "| ** *Computer win!! Bad Luck!|"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

comp_goaltotal=0

 

else:

print "PLEASE ENTER A VALID INPUT!!!"

temp_total_comp = comp_goaltotal

print"| ------------------- End Computer's Turn -----------------------"

 

STEP6

 

from random import randint

proceed = "r"

flag = 0

die_turntotal = 0

temp_total_player = 0

temp_total_comp = 0

player_goaltotal = 0

comp_goaltotal = 0

play = raw_input("Would you like to play PIG (y/n)?")

if play == "y":

name = raw_input("Great! What is your name?")

print "Hi {0}!".format(name)

while player_goaltotal < 100 and comp_goaltotal < 100 :

proceed = "r"

print "|------------------- Start Player's Turn ---------------------"

die_turntotal = 0

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))

die2 = (randint(1,6))

dietotal_player = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal_player)

die_turntotal = die_turntotal + dietotal_player

dietotal_player = 0

player_goaltotal = temp_total_player + die_turntotal

if die1 == 1 and die2 == 1:

proceed = "losetotal"

player_goaltotal = 0

elif die1 == 1 or die2 == 1:

proceed = "loseall"

player_goaltotal = player_goaltotal - die_turntotal

elif player_goaltotal >= 100:

proceed = "win"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal, player_goaltotal)

 

if proceed == "h":

print "| *** Hold!"

player_goaltotal = temp_total_player + die_turntotal

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal,comp_goaltotal)

elif proceed == "losetotal":

print "| *** You rolled two ONEs - You lose all points!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal,comp_goaltotal)

elif proceed == "loseall":

print "| *** You rolled a ONE - Turn over - No points for you!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

elif proceed == "win":

flag = 1

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

print "| ** *You win!! Congratulations!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

else:

print "PLEASE ENTER A VALID INPUT!!!"

temp_total_player = player_goaltotal

print"| ------------------- End Player's Turn -----------------------"

 

if flag != 1:

print "|------------------- Start Computer's Turn ---------------------"

proceed = "r"

die_turntotal = 0

while proceed == "r":

die1 = (randint(1, 6))

die2 = (randint(1, 6))

dietotal_comp = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1, die2, dietotal_comp)

die_turntotal = die_turntotal + dietotal_comp

dietotal_comp = 0

comp_goaltotal = temp_total_comp + die_turntotal

 

if die1 == 1 and die2 == 1:

proceed = "losetotal"

comp_goaltotal = 0

elif die1 == 1 or die2 == 1:

proceed = "loseall"

comp_goaltotal = comp_goaltotal - die_turntotal

else:

if die_turntotal >= 20:

proceed = "h"

comp_goaltotal = temp_total_comp + die_turntotal

if comp_goaltotal >= 100:

proceed = "win"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal, comp_goaltotal)

 

if proceed == "h":

print "| *** Hold!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "losetotal":

print "| *** Computer rolled two ONEs - Computer loses all points!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "loseall":

print "| *** Computer rolled a ONE - Turn over - No points for Computer!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "win":

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

print "| ** *Computer win!! Bad Luck!|"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

else:

print "PLEASE ENTER A VALID INPUT!!!"

temp_total_comp = comp_goaltotal

print"| ------------------- End Computer's Turn -----------------------"

 

if player_goaltotal >= 100 and proceed != "win":

print "| ** *You win!! Congratulations!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

elif comp_goaltotal >= 100 and proceed != "win":

print "| ** *Computer win!! Bad Luck!|"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal )

 

elif play =="n":

print "HAVE A GOOD DAY!"

else:

print "PLEASE ENTER A VALID INPUT!!!"

STEP7 & STEP8

 

from random import randint

import sys

proceed = "r"

flag = 0

die_turntotal = 0

temp_total_player = 0

temp_total_comp = 0

player_goaltotal = 0

comp_goaltotal = 0

play = raw_input("Would you like to play PIG (y/n)?")

if play == "y":

name = raw_input("Great! What is your name?")

print "Hi {0}!".format(name)

while player_goaltotal < 100 and comp_goaltotal < 100 :

proceed="r"

print "|------------------- Start Player's Turn ---------------------"

die_turntotal = 0

while proceed == "r":

proceed = raw_input("| Would you like to roll or hold (r/h)?")

if proceed == "r":

die1 = (randint(1,6))#To generate random numbers

die2 = (randint(1,6))

dietotal_player = die1 + die2

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1,die2,dietotal_player)

die_turntotal = die_turntotal + dietotal_player

dietotal_player = 0

player_goaltotal = temp_total_player + die_turntotal#To calaculate goal total

if die1 == 1 and die2 == 1:

proceed = "losetotal"

player_goaltotal = 0

elif die1 == 1 or die2 == 1:

proceed = "loseall"

player_goaltotal = player_goaltotal - die_turntotal

elif player_goaltotal >= 100:

proceed = "win"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal, player_goaltotal)

 

if proceed == "h":#For hold condition

print "| *** Hold!"

player_goaltotal = temp_total_player + die_turntotal

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal,comp_goaltotal)

elif proceed == "losetotal":# Two ones ooccuring condition

print "| *** You rolled two ONEs - You lose all points!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal,comp_goaltotal)

elif proceed == "loseall":#One one occuring condition

print "| *** You rolled a ONE - Turn over - No points for you!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

elif proceed == "win":

flag = 1

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

print "| ** *You win!! Congratulations!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

player_goaltotal=0#Reset the total goal score .Used if request for replay is given

else:

print "PLEASE ENTER A VALID INPUT!!!"

temp_total_player = player_goaltotal

print"| ------------------- End Player's Turn -----------------------"

 

if flag != 1:#To stop after player wins

print "|------------------- Start Computer's Turn ---------------------"

proceed = "r"

die_turntotal = 0

while proceed == "r":

die1 = (randint(1, 6))#Random generation of numbers for die's

die2 = (randint(1, 6))

dietotal_comp = die1 + die2#Add dies in one throw

print "| Die 1: {0} | Die 2:{1} | Die total: {2}".format(die1, die2, dietotal_comp)

die_turntotal = die_turntotal + dietotal_comp#Total tuen score

dietotal_comp = 0

comp_goaltotal = temp_total_comp + die_turntotal#Total potential score calculation

 

if die1 == 1 and die2 == 1:

proceed = "losetotal"

comp_goaltotal = 0

elif die1 == 1 or die2 == 1:

proceed = "loseall"

comp_goaltotal = comp_goaltotal - die_turntotal

else:

if die_turntotal >= 20:#Hold at 20 policy

proceed = "h"

comp_goaltotal = temp_total_comp + die_turntotal

if comp_goaltotal >= 100:#Goal policy

proceed = "win"

else:

print "| Turn total: {0} | Potential score: {1}\n|".format(die_turntotal, comp_goaltotal)

 

if proceed == "h":

print "| *** Hold!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "losetotal":

print "| *** Computer rolled two ONEs - Computer loses all points!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "loseall":

print "| *** Computer rolled a ONE - Turn over - No points for Computer!"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

elif proceed == "win":

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

print "| ** *Computer win!! Bad Luck!|"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal)

print"| ** ** ** ** ** ** ** ** ** ** ** *GAMEOVER ** ** ** ** ** ** ** ** ** ** ** ** ** *"

comp_goaltotal=0

 

else:

print "PLEASE ENTER A VALID INPUT!!!"

temp_total_comp = comp_goaltotal

print"| ------------------- End Computer's Turn -----------------------"

if proceed == "win":

playagain = raw_input("Would you like to play again?(y/n)")#Request to play again

if playagain == "y":

proceed = "r"

flag = 0

player_goaltotal = 0

comp_goaltotal = 0

temp_total_comp=0

temp_total_player=0

else:

print "HAVE A GOOD DAY!"

sys.exit(0)#exits

if player_goaltotal >= 100 and proceed != "win":

print "| ** *You win!! Congratulations!"

print "| *** {0}'s score: {1} | Computer's score: {2}".format(name,player_goaltotal, comp_goaltotal)

elif comp_goaltotal >= 100 and proceed != "win":

print "| ** *Computer win!! Bad Luck!|"

print "| *** Computer's score: {0} | {1}'s score: {2}".format(comp_goaltotal,name,player_goaltotal )

 

elif play =="n":

print "HAVE A GOOD DAY!"#If user selects no

else:

print "PLEASE ENTER A VALID INPUT!!!"#If any other input other than requested ones are given

Find Solution for Programming assignment by dropping us a mail at help@myassignmentservices.com.au along with the question’s URL. Get in Contact with our experts at My Assignment Services AU and get the solution as per your specification & University requirement.

RELATED SOLUTIONS

Order Now

Request Callback

Tap to ChatGet instant assignment help

Get 500 Words FREE