Question

Add a while loop to this code so that it will replay the Game of Life....

  1. Add a while loop to this code so that it will replay the Game of Life. Be sure to ask the user if they want to play again and exit the loop if they say no.

print("Welcome to the Game of Life!")

print("A. Banker")

print("B. Carpenter")

print("C. Farmer")

user_input = input("What is your occupation? ")

if user_input == "A":

    money = 100

elif user_input == "B":

    money = 70

elif user_input == "C":

    money = 50

print("Great! you will start the game with", money, "dollars.")

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

Program:

while True:
print("Welcome to the Game of Life!")
print("A. Banker")
print("B. Carpenter")
print("C. Farmer")
user_input = input("What is your occupation? ")
if user_input == "A":
money = 100
elif user_input == "B":
money = 70
elif user_input == "C":
money = 50
print("Great! you will start the game with", money, "dollars.")
x=input(" \n Do You want to play again? Enter Yes or No.")
if x == "No":
break

Output:

Add a comment
Know the answer?
Add Answer to:
Add a while loop to this code so that it will replay the Game of Life....
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
  • A simple game of chance Using a while loop write a simple coin flip game. Specifics:...

    A simple game of chance Using a while loop write a simple coin flip game. Specifics: The user starts with a bank of $10.00 It costs a dollar to play A correct guess pays $2.00 The while loop is used for the game loop. It should ask if the user wants to play. The while loop will check for a value of 'Y' or 'N'. You should also allow for lower case letters to be input. You MUST prime the...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    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...

  • This question deals with extending already existing Java code via a while loop. Ask the user...

    This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...

  • A Backwards Guessing Game For this assignment, you will be a making a guessing game with...

    A Backwards Guessing Game For this assignment, you will be a making a guessing game with a twist. You will play the role of the computer, and the computer will try to guess the number. You will think of a number (you don’t have to read it in as input) between 1 and 100. You will create a loop that runs 5 times. In this loop, the computer will try to guess the number in the range it knows is...

  • I need help on creating a while loop for my Java assignment. I am tasked to...

    I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...

  • C++ code do while loop issue. The code I posted works but when it prompts the...

    C++ code do while loop issue. The code I posted works but when it prompts the user if they want to try against with another sentence, it only takes the Y and goes straight into another loop, without letting me enter a new sentence. I need it to be able to take the Y response from a user and then let me enter another sentence. do { cout<<"Enter a sentence:"; //user input sentence cin.getline(str,80); int wordsCount = 0; for (int...

  • Go back to In Class Lab A where you created a Game Menu. Modify your code...

    Go back to In Class Lab A where you created a Game Menu. Modify your code so that the user can input one of the four choices. Use an if/else statement so that depending on the user’s choice, the correct game will play. If the user inputs a 4 (Exit), your code exits without playing any game. For the MATH and MADLIBS choices, use your code from Lab 1. For the CHOOSE YOUR OWN ADVENTURE choice, write the code. Write...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

  • Java code. Need help with either 1. or 2. Nothing too complicated and the code needs...

    Java code. Need help with either 1. or 2. Nothing too complicated and the code needs at least one loop and 3 switch statements! Artificial Intelligence elements in programming. Creating stories with user input. For this assignment, you can do one of two things 1. Create a chat box that allows a conversation to go on as long as the user wants . Welcome the user when they start. . look for key words or other things that could guide...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

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