Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Volleyball game
#9
I am still struggling. I can't figure out how to put it all together.

def match(Home, Visitor, matchnum):
      print("Match", str(matchnum))
      scorehome = int(input("Enter the number of points "+Home+" got in Match "+str(matchnum)+": "))
      scorevisitor = int(input("Enter the number of points "+Visitor+" got in Match "+str(matchnum)+": "))
      wrong_score()
 

def printScoreCard(Home,Visitor,winhome,winvisitor):
      print(Home,winhome)
      print(Visitor, winvisitor)
def wrong_score():
      if scorehome > scorevisitor and scorehome < 25:
            print("One team must score 25 points. Please enter scores again.")
            return False
      elif scorevisitor > scorehome and scorevisitor < 25:
            print("One team must score 25 points. Please enter scores again.")
            return False
      elif scorehome > scorevisitor and scorehome - scorevisitor < 2:
            print("One team must win by 2 points. Please enter scores again.")
            return False
      elif scorevisitor > scorehome and scorevisitor - scorehome < 2:
            print("One team must win by 2 points. Please enter scores again.")
            return False
      elif scorehome > scorevisitor:
            winhome=winhome+1
            return True
      else:
            scorevisitor > scorehome
            winvisitor= winvisitor+1
            return True          

      
def startgame():
      print("Welcome to the volleyball score program.")
      Home = input("Enter the home team's name: ")
      Visitor = input("Enter the visitor's team name: ")
      winhome = 0
      winvisitor = 0
      for i in range(5):
            while True:
                  scorehome,scorevisitor=match(Home, Visitor,i+1)
                  if wrong_score():
                        break
            printScoreCard(Home,Visitor,winhome,winvisitor)
            
             
      if winhome>winvisitor:
            print(Home+" wins the game!")
      else:
            print(Visitor+" wins the game!")      
startgame()
Reply


Messages In This Thread
Volleyball game - by DrewD - Dec-11-2017, 05:34 AM
RE: Volleyball game - by j.crater - Dec-11-2017, 06:51 AM
RE: Volleyball game - by DrewD - Dec-11-2017, 07:25 PM
RE: Volleyball game - by j.crater - Dec-11-2017, 07:44 PM
RE: Volleyball game - by DrewD - Dec-12-2017, 02:52 AM
RE: Volleyball game - by j.crater - Dec-13-2017, 06:21 AM
RE: Volleyball game - by DrewD - Dec-13-2017, 05:09 PM
RE: Volleyball game - by j.crater - Dec-13-2017, 06:49 PM
RE: Volleyball game - by DrewD - Dec-14-2017, 07:23 PM
RE: Volleyball game - by DrewD - Dec-15-2017, 03:06 AM
RE: Volleyball game - by j.crater - Dec-16-2017, 09:41 AM
RE: Volleyball game - by DrewD - Dec-17-2017, 04:15 AM
RE: Volleyball game - by Terafy - Dec-17-2017, 04:48 AM
RE: Volleyball game - by Terafy - Dec-17-2017, 05:39 AM
RE: Volleyball game - by DrewD - Dec-17-2017, 07:28 PM
RE: Volleyball game - by Terafy - Dec-17-2017, 07:59 PM
RE: Volleyball game - by DrewD - Dec-17-2017, 08:22 PM
RE: Volleyball game - by Terafy - Dec-17-2017, 08:28 PM

Forum Jump:

User Panel Messages

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