Python Forum
Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me)
#4
To test the play again logic try entering something other than Yes or No. I guess I did a typo (probably just Y or N) when I tested. Your logic has three possible outcomes; quit, replay with a new word; replay with the old word already solved.

Your replay logic is in the wrong place and that is why you have to use sys.exit to quit the program. The main body of the program should manage the replay logic and the run function should implement the game logic. By removing the replay logic from the run function you can initialize the game at the top of the run function, removing the initialization stuff from the random_word function (or removing the random word function).
"""Hangman game"""
import random

def play_game():
    """Player enters guesses until all letters in word are guessed"""
    # Initialize word, guesses, etc
    while '_' in list_space1:
        # get guess
        # process guess
    print('You guessed the word!')

while True:
    play_game()
    if input('Would you like to play again (y/n)? ').upper()[0] == 'N':
        print('Thanks for playing!')
        break;
If you don't want to reorganize the replay logic you can still get rid of the sys.exit() call. In run:
if ask.upper()[0] == 'Y':
    random_word()
else:
    run_game = False
    return
Still so ugly.
Reply


Messages In This Thread
RE: Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me) - by deanhystad - Jul-07-2020, 01:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to improve a programm Richard_SS 4 2,809 Mar-17-2019, 04:16 AM
Last Post: Richard_SS
  Help on Creating Program to find the Median and Mode by hand EvanCahill 3 2,947 Jul-19-2018, 06:17 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020