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!")
def guessingGame():
min_number=1
max_number=10
#set number of guesses = 0
numGuesses=0
rand=random.randint(min_number, max_number)
#prints the header, welcoming the user
print("\nWelcome to the Guess My Number Program!")
#While loop, comparing the users guessed number with the random
number.
#If it matches, it will say you guessed it.
while (True):
#use try-block
try:
guess=eval(input("Please try to guess my number between 1 and
10:"))
#check if the guess is less than 0, then continye to beginning of
the loop
if(guess<0):
continue;
elif (guess==rand):
#increment the guess count by 1
numGuesses=numGuesses+1
print("You guessed it! It took you ", numGuesses,"attempts")
#break will end the loop once the guess is a match.
#Conditions if the guess is too low or too high to keep
guessing
break
elif(guess < rand):
#increment the guess count by 1
numGuesses = numGuesses +1
print("Too low")
else:
#increment the guess count by 1
numGuesses = numGuesses + 1
print("Too high")
except:
#print exception
print("Numbers only!")
def guessingGameComp():
countGuess=0
userNumber=int(input("\nPlease enter a number between 1 and 10 for
the computer to guess:"))
while userNumber<1 or userNumber>10:
userNumber=int(input("Guess a number between 1 and 10: "))
while True:
countGuess+=1
compRand = random.randint(1,10)
if(userNumber==compRand):
print("The computer guessed it! It took {}
attempts".format(countGuess))
break
elif(userNumber<compRand):
print("The computer guessed {} which is too
low".format(compRand))
else:
print("The computer guessed {} which is too
high".format(compRand))
def main():
while True:
userChoice=menu()
if userChoice==1:
guessingGame()
elif userChoice==2:
guessingGameComp()
elif userChoice==3:
print("\nThank you for playing the guess the number game!")
break
else:
print("Invalid choice!!!")
main()
IPO Chart
Inputs |
Process (calculations) |
Outputs |
IPO chart for guessingGame
Input |
Processing |
Output |
Guess |
a. If the guess is less than 0, then continue to beginning of the loop and increment number of guesses b. If guess is equal to random number then print success message, increment guess count and break out of loop c. If guess is less than the number print “too low” and increment counter d. If guess is greater than the number print “too high” and increment counter
|
Number of guesses |
IPO chart for guessingGameComp
Input |
Processing |
Output |
Number |
a. Increment guess counter b. Generate a random number between 1 and 10 c. If the guess is equal to the number then break d. If guess is less than the number print “computer guessed too low” e. If guess is greater than the number print “computer guessed too high”
|
Number of guesses |
Can you please enter this python program code into an IPO Chart? import random def menu():...
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...
FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess: if int(YourNumber) == number: print("YAY, You have guessed my number") else: unusedguesses=int(guess)-1 if unusedguesses == 0: break else: print("Try again!") print("The number was ", str(number))
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...
Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...
python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try: f = open("shopping2.txt","r") for line in f: sl.append(line.strip()) f.close() except: pass def mainScreen(): os.system('cls') # for linux 'clear' print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(" SHOPPING LIST ") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("\n\nYour list contains",len(sl),"items.\n") print("Please choose from the following options:\n") print("(a)dd to the list") print("(d)elete from the list") print("(v)iew the...
WEEK 6: COURSE PROJECT The Week 6 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details. Use this report (Links to an external site.)Links to an external site. to complete this portion of the project. Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add...
List of keywords in Python can be obtained with the statements import keyword kw = keyword.kwlist Use list comprehension to print out a lower case sorted 2-column list. The output should look as follows: and as assert async await break class continue def del elif else false except finally for from global if import in is lambda none nonlocal not or pass raise return try true while with yield and as assert async await break class continue def del elif...
Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk() self.main.title("mine sweeper") self.define_widgets() self.mines = random.sample( [(i,j) for i in range(25) for j in range(50) ],self.CustomizeNumberOfMines()) print(self.mines) self.main.mainloop() self.CustomizeNumberOfMines() def define_widgets(self): """ Define a canvas object, populate it with squares and possible texts """ self.canvas = tk.Canvas(self.main, width = 1002, height=502, bg="#f0f0f0") self.canvas.grid(row=0, column=0) self.boxes =...
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...
In python this is what I have for task 3, but I don't know how to fix it so that the computer stops picking from the pile once it reaches zero Task 3: Extend the game to have two piles of coins, allow the players to specify which pile they take the coins from, as well as how many coins they take Finish Task 3 and try three test cases import random remaining_coins1 = 22 remaining_coins2 = 22 while 1:...