def st_petersburg_lottery():
print("###### St. Petersburg Lottery ######")
print("Instructions:")
print("You will select any number greater than 0.")
print("Up to the number of times you chose, we will randomly choose
0 or 1.")
print("If a 1 is chosen before the last drawing, then you
lose.")
print("If a 1 does not appear at all, then you lose.")
print("You win if 1 is chosen for the first time exactly on the
last drawing.")
print()
def first_to_a_word():
print("###### First to a Word ######")
print("Instructions:")
print("You will take turns choosing letters one at a time until a
word is formed.")
print("After each letter is chosen you will have a chance to
confirm whether or not a word has been formed.")
print("When a word is formed, the player who played the last letter
wins!")
print("One of you has been chosen at random to initiate the
game.")
print()
print("Note: Words must be longer than a single letter!")
print()
def game_of_21():
print("###### Game of 21 ######")
print("Instructions:")
print("Starting from 1, you will take turns saying a number that is
1, 2, or 3 greater than the previous number.")
print("The first player always starts by saying 1.")
print("The player who says 21 loses.")
print("You may not say a number greater than 21.")
print("One of you has been chosen at random to initiate the
game.")
print()
def display_menu():
# You should write all the code for the Menu Display
function below this.
# Remember to make sure that the output is correct! (For example,
items are displayed in the correct order)
# Don't forget to use the "skeleton" of the code in main to
remember whether this function should or should not return
something!
print("~=[Menu]=~") # FINISH IMPLEMENTING THIS FUNCTION
def main():
# Below you will find comments that you are supposed to
replace with code.
# You should not need to change anything other than inserting code
into those spots.
# Note: This main is meant to give you a solid starting point on
the rest of the assignment!
# Think about why/how we call certain functions at certain points
to get context clues that could help in implementing the
functions!
print("Welcome to the Game of Chance!")
still_playing = # fill me in! # 1) initialize tracker
variable
while # FILL ME IN!: # 2) are we done?
print()
game_chosen = 4 # You will call your display_menu()
function here when you move to development step 2
if game_chosen == 1:
st_petersburg_lottery()
elif game_chosen == 2:
first_to_a_word()
elif game_chosen == 3:
game_of_21()
else:
print("We will now exit the Game of Chance.")
still_playing = # fill me in! # 3) update the still_playing
value appropriately so that your loop will stop!
print("Thank you for playing!")
Thanks for the question, I have implemented the section with code where ever we had comments.
Let me know for any questions or help.
thank you !
=============================================================================
def st_petersburg_lottery():
print("###### St. Petersburg Lottery
######")
print("Instructions:")
print("You will select any number
greater than 0.")
print("Up to the number of times you
chose, we will randomly choose 0 or 1.")
print("If a 1 is chosen before the last
drawing, then you lose.")
print("If a 1 does not appear at all,
then you lose.")
print("You win if 1 is chosen for the
first time exactly on the last drawing.")
print()
def first_to_a_word():
print("###### First to a Word
######")
print("Instructions:")
print("You will take turns choosing
letters one at a time until a word is formed.")
print("After each letter is chosen you
will have a chance to confirm whether or not a word has been
formed.")
print("When a word is formed, the player
who played the last letter wins!")
print("One of you has been chosen at
random to initiate the game.")
print()
print("Note: Words must be longer than a
single letter!")
print()
def game_of_21():
print("###### Game of 21
######")
print("Instructions:")
print("Starting from 1, you will take
turns saying a number that is 1, 2, or 3 greater than the previous
number.")
print("The first player always starts by
saying 1.")
print("The player who says 21
loses.")
print("You may not say a number greater
than 21.")
print("One of you has been chosen at
random to initiate the game.")
print()
def display_menu():
# You should write all the code for the Menu Display function
below this.
# Remember to make sure that the output is correct! (For example,
items are displayed in the correct order)
# Don't forget to use the "skeleton" of the code in main to
remember whether this function should or should not return
something!
print("~=[Menu]=~") #
FINISH IMPLEMENTING THIS FUNCTION
print('[1] St Petersburg
Lottery')
print('[2] First to a
Word')
print('[3] Game of 21')
print('[4] Quit')
choice = int(input('Enter your choice:
'))
return choice
def main():
# Below you will find comments that you are
supposed to replace with code.
# You should not need to change anything other
than inserting code into those spots.
# Note: This main is meant to give you a solid
starting point on the rest of the assignment!
# Think about why/how we call certain functions
at certain points to get context clues that could help in
implementing the functions!
print("Welcome to the Game of
Chance!")
still_playing = True# fill
me in! # 1) initialize tracker variable
while still_playing: #
FILL ME IN!: # 2) are we done?
print()
game_chosen =
display_menu() # You will call your display_menu() function
here when you move to development step 2
if
game_chosen == 1:
st_petersburg_lottery()
elif
game_chosen == 2:
first_to_a_word()
elif
game_chosen == 3:
game_of_21()
else:
print("We will now exit the Game of
Chance.")
still_playing =
False # fill me in! # 3) update the
still_playing value appropriately so that your loop will
stop!
print("Thank you for
playing!")
main()
def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.")...
Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================") def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...
HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUYS HELPS ME OUT ON HOW TO TEST A SIMPLE CODE SINCE ITS A GUESSING GAME! THANK YOU. PYTHON import random # here it allows us to use the benefits of the functions random #function 1 which is just a screen organized wordings def screen): screeninstructions () name input("Your Name : ") print('Welcome, name, 'This...
: back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von AwNP Complete the get_message function so if user_num is equal to rand_num, return "You picked the same number as the computer!" if user_num is less than rand_num, return "Your number is smaller than the computer's number." if user_num is greater than rand_num, return "Your number is higher than the computer's number." Comment out the call to main when trying to pass the tests. 11...
Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...
Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...
Can you please Test and debug the program below using the following specifications? Many thanks! Create a list of valid entries and the correct results for each set of entries. Then, make sure that the results are correct when you test with these entries. Create a list of invalid entries. These should include entries that test the limits of the allowable values. Then, handle the invalid integers (such as negative integers and unreasonably large integers). In addition, make sure the...
can this code be provided? Project #3 Introduction As you wrap up with JavaScript, let's put together everything you've learned to make the classic game "Hangman" in a webpage. If you are unfamiliar with the rules of Hangman, the game works like this: A gallows is drawn on a surface, and Player 1 chooses a word that player 2 must guess. Empty dashes for each letter in the word are drawn next to the gallows (so a 7-letter word means...
5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may recognize Rock Paper Scissors Lizard Spock as a game of chance that expands on the standard Rock Paper Scissors game. It introduces two new hand signs and several more rules. The rules: • Scissors cuts Paper • Paper covers Rock • Rock crushes Lizard • Lizard poisons Spock • Spock smashes Scissors • Scissors decapitates Lizard • Lizard eats Paper • Paper disproves Spock...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...