Question
Coding in Python. Here is the error message I recieve from my test: ERROR: test_main (__main__.TestConditions) ---------------------------------------------------------------------- Traceback (most recent call last): File /Users/test_pig.py, line
Coding in Python. Here is the error message I recieve from my test:
ERROR: test_main (__main__.TestConditions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/test_pig.py", line 129, in test_main
infile = open('intest.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'intest.txt'
======================================================================
FAIL: test_check_for_winner (__main__.TestConditions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/test_pig.py", line 26, in test_check_for_winner
self.assertEqual("THE WINNER IS: Ziggy!!!!! ", buf.getvalue())
AssertionError: 'THE WINNER IS: Ziggy!!!!! ' != 'THE WINNER IS: Ziggy !!!!! '
- THE WINNER IS: Ziggy!!!!!
+ THE WINNER IS: Ziggy !!!!!
? +
======================================================================
FAIL: test_play_turn (__main__.TestConditions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/test_pig.py", line 84, in test_play_turn
"\t<<< Henry rolls a 2 >>> \tPoints: 10 ", buf.getvalue())
AssertionError: "---------- Henry's turn ---------- \t<<< Henry rolls a 2[96 chars]10 " != "---------- Henry 's turn ---------- <<< Henry roll[121 chars]10 "
- ---------- Henry's turn ----------
+ ---------- Henry 's turn ----------
? +
- <<< Henry rolls a 2 >>>
? ^
+ <<< Henry rolls a 2 >>>
? ^^^^^^
- Points: 2
+ Points: 2
- <<< Henry rolls a 6 >>>
? ^
+ <<< Henry rolls a 6 >>>
? ^^^^^^
- Points: 8
+ Points: 8
- <<< Henry rolls a 2 >>>
? ^
+ <<< Henry rolls a 2 >>>
? ^^^^^^
- Points: 10
? ^
+ Points: 10
? ^^^^^^
======================================================================
FAIL: test_print_scores (__main__.TestConditions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/test_pig.py", line 20, in test_print_scores
self.assertEqual(" --- SCORES\tZiggy: 18\tElmer: 23 --- ", buf.getvalue())
AssertionError: ' --- SCORES\tZiggy: 18\tElmer: 23 --- ' != '--- SCORES Ziggy : 18 Elmer : 23 --- '
-
- --- SCORES Ziggy: 18 Elmer: 23 ---
? ^ ^
+ --- SCORES Ziggy : 18 Elmer : 23 ---
? + ^^^^^ + + ^^^^^^^^ +
======================================================================
FAIL: test_roll_again (__main__.TestConditions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/test_pig.py", line 57, in test_roll_again
'Please enter either "Y" or "N". ', buf.getvalue())
AssertionError: 'I don\'t understand: "Never". Please enter either "Y" or "N". ' != 'I don\'t understand: Elmer . Please enter either "Y" or "N". '
- I don't understand: "Never". Please enter either "Y" or "N".
? ^^^^ ^
+ I don't understand: Elmer . Please enter either "Y" or "N".
? ^^^ ^
----------------------------------------------------------------------
Ran 5 tests in 0.008s
FAILED (failures=4, errors=1)
Correctness score = 0.0%
Can you please identify and fix my errors? Here is my code:
import random # put all of your function definitions below this line and then delete this comment def print_scores(name1, score1, name2, score2): name1=str(name1) name2=str(name2) print('--- SCORES ', name1, ': ', score1, ' ', name2, ':', score2, '---') return None
def check_for_winner(name, score): if score >= 50: print ("THE WINNER IS:",name,"!!!!!") return True else: return False
def roll_again(name): a = input('Roll again? (Y/N) ') while a != 'Y' and a != 'y' and a != 'N' and a != 'n': print('I don\'t understand:', name,'. Please enter either "Y" or "N".') a = input('Roll again? (Y/N) ') if a == 'Y' or a == 'y': return True elif a == 'N' or a == 'n': return False
def play_turn(name): n = 0 print('----------', name,"'s turn", '----------') i = random.randint(1, 6) if i != 1: n = n + i print(' ', '<<<', name, 'rolls a', i, '>>>') print(' Points:', i) else: print(' !!! PIG! No points earned, sorry', name) print('(enter to continue)') while roll_again(name): i = random.randint(1, 6) if i != 1: n = n + i print(' ', '<<<', name, 'rolls a', i,'>>>') print(' Points:', n) else: print(' !!! PIG! No points earned, sorry', name) n = 0 input('(enter to continue)') print() return n
#========================================================== def main(): ''' Write a description of what happens when you run this file here. ''' # put main code here, make sure each line is indented one level, and delete this comment
input('Enter seed value: ') print() print() print('Pig Dice') name1 = input('Enter name for player 1: ') name2 = input('Enter name for player 2: ') print('Hello', name1, 'and', name2, 'welcome to Pig Dice!') print() score1 = 0 score2 = 0 name = name1 score = score1 k = 1 print_scores(name1, score1, name2, score2) play_turn(name) d = input while d == 'N' or d == 'n': print_scores(name1, score1, name2, score2) play_turn(name1) if n < 50: k = k + 1 if k % 2 == 0: name = name2 score = score2 else: name = name1 score = score1 else: check_for_winner(name, score)
if check_for_winner == False: play_turn(name2) if n < 50: k = k + 1 if k % 2 == 0: name = name2 score = score2 else: name = name1 score = score1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started