Question
python question
Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to
Enter a number between 1 and 50: 48 Congratulations!!! You win in 4 tries. Sample input/output for this game, where the user

250 To play the game, each player enters her/his name and a number from 1 to 200. The computere, your program) chooses, rando


• function displayMenu which displays the menu (given below), allows the user to choose a game to be played and returns the n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

import random
def guessTheNumber():
print("\nLet us play Guess the Number!")
print("I am thinking of a number between 1 and 50(inclusive)")
print("Try to guess the number and i will give you hints along the way")
print("You have at most 5 tries to guess the number.")
secretNumber=random.randint(1, 50)

numTires=0

while numTires!=5:
numTires+=1
win=False
guess=int(input("\nEnter a number between 1 and 50: "))
if(guess==secretNumber):
print("\nCongratualations!!! You win in {} tries.".format(numTires))
win=True
break
elif(guess<secretNumber):
print("Too low! Guess a number higher than {}".format(guess))
else:
print("Too high! Guess a number lower than {}".format(guess))
if(numTires==5 and win==False):
print("\nGame Over. You used up all 5 tires.")
print("The number was {} - better luck next time!")

def getPoints(userNum, rndCircleNum):
points=[100,50,65,75]
if rndCircleNum==1:
if userNum>=1 and userNum<=50:
return 100
if rndCircleNum==2:
if userNum>=51 and userNum<=100:
return 50
if rndCircleNum==3:
if userNum>=101 and userNum<=150:
return 65
if rndCircleNum==4:
if userNum>=151 and userNum<=200:
return 75
if rndCircleNum==1:
return (userNum-50)/2

if rndCircleNum==2:
if userNum<51:
return points[rndCircleNum-1]/2
else:
return (userNum-100)/2

if rndCircleNum==3:
if userNum<101:
return points[rndCircleNum-1]/2
else:
return (userNum-150)/2

if rndCircleNum==4:
if userNum<151:
return points[rndCircleNum-1]/2

def aimForTraget():
name1=input("\nPlayer 1 enter you first name: ")
print("{} please enter a number bewtween a number 1 and 200 inclusive: ".format(name1),end="")
num1=int(input())
name2=input("Player 2 enter you first name: ")
print("{} please enter a number bewtween a number 1 and 200 inclusive: ".format(name2),end="")
num2=int(input())

randomCircle1=random.randint(1,4)
randomCircle2=random.randint(1,4)

player1Point=getPoints(num1,randomCircle1)
player2Point=getPoints(num2,randomCircle2)

print("Points for {} are {}".format(name1,player1Point))
print("Random circle for Player 1 was: {}".format(randomCircle1))
print("Points for {} are {}".format(name2,player2Point))
print("Random circle for Player 2 was: {}".format(randomCircle2))

if(player1Point>player2Point):
print("{} wins".format(name1))
elif(player1Point<player2Point):
print("{} wins".format(name2))
else:
print("It is a tie!")

def displayMenu():
print("Choose one of the following games to play")
print("1. Guess the Number")
print("2. Aim for the Traget")
choice=int(input("Enter your choice of game as 1 or 2: "))
return choice

def main():
while True:
userChoice=displayMenu()
if(userChoice==1):
while True:
guessTheNumber()
again=input("\nDo you wish to play again? Enter y or n: ")
if(again=='n'):
print()
break
elif(userChoice==2):
while True:
aimForTraget()
again=input("\nDo you wish to play again? Enter y or n: ")
if(again=='n'):
print()
break
if(again=='n' and userChoice==2):
break
print("Goodbye. Hope you enjoyed playing!")

if __name__ == '__main__':
main()

outputC. Command Prompt - x D:\Chegg\Python>py fun_games.py Choose one of the following games to play 1. Guess the Number 2. Aim fo- 5 x C. Command Prompt Choose one of the following games to play 1. Guess the Number 2. Aim for the Traget Enter your choice

code snapsSo woww fun_games.py 1 import random 2 v def guess TheNumber(): print(\nLet us play Guess the Number!) print(I am thinkingreturn 100 if rndCircleNum==2: if userNum>=51 and userNum<=100: return 50 if rndcircleNum==3: if userNum>=101 and user Num<=162 def aimForTraget(): name1=input(\nPlayer 1 enter you first name: ) print({} please enter a number bewtween a number 1 adef displayMenu(): print(Choose one of the following games to play), print(1. Guess the Number) print(2. Aim for the Tra

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
python question Question 1 Write a Python program to play two games. The program should be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Specification Write a program that allows the user to play number guessing games. Playing a Guessing...

    Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...

  • Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts...

    Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing.      Guess my number between 1 and 1000 => 500      Too high...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • In Java You’re going to make a Guess the Number game. The computer will "think" of...

    In Java You’re going to make a Guess the Number game. The computer will "think" of a secret number from 1 to 20 and ask the user to guess it. After each guess, the computer will tell the user whether the number is too high or too low. The user wins if they can guess the number within six tries. The program should look like this in the console, player input is in bold: Hello! What is your name? Abaddon...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • on python i need to code a guessing game. After the player has guessed the random...

    on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • For this lab you will write a Java program using a loop that will play a...

    For this lab you will write a Java program using a loop that will play a simple Guess The Number game. Th gener e program will randomly loop where it prompt the user for a ate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a r has guessed the correct number, the program will end with a message indicating how many guesses it took to get the right answer and a...

  • Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask...

    Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask user for a guess; possible answers TOO LOW TOO HIGH WINNER! print guess to screen if the user wins, write the random number, and all the guesses to a file. If the user doesn't guess in 10 turns, display the number. NOTES: You may want to implement: Restart option Best Guess statistic (game 1 took 8 tries, game 2 took 5 - 5 is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT