Dear Python Tutor:
Well,I am Stephen Mik,and I'm a beginning,rookie programmer who is just
trying to get a class Assignment going. The instructor of my class does not
accept email and she is not on Campus on Monday. So,my only recourse is to turn
to Python Tutor for assistance.
My program, Assignment4,does run partially. You can see the results of the
Python Shell attached to this email. I also have included part of my code for
your perusal.
I must be doing something very wrong. The program is supposed to run a main
loop ,for control of the program. The program DOES print out the prompts before
the While Loop, but when it comes to a variable named"smv_guessNumber" the
program DOES NOT prompt for the input for "smv_guessNumber" as it should. It is
a mystery to me as to why the program will not get to the
"smv_guessNumber=int(input("Think out a first guess:")". I am mystified why it
doesn't reach that point in the program! Can anyone please help? I have
attached the Python Traceback Error Output,which shows that at least part of
the program IS working. I also have attached part of the code for the
Assignment 4 which should help in the debugging.I need help ASAP,another
program is due very soon and I have not even worked out the pseudocode for it
yet!
CONCERNED,Stephen W. Mik
#CS 110A Spring 2014 Sect 4988 Assignment 4
#MODIFIED GUESS MY NUMBER PROGRAM
#Date April ,2014
#Programmer Stephen W. Mik
#This program is modified after a version found
#in the TextBook "Python Programming 3rd Edition"
#by Michael Dawson Copyright 2010;ISBN-13: 978-1-4354-5500-9
#Or the Alternate ISBN-10: 1-4354-5500-2.
#It is based on the material found on page 50,and pages 81-84
#of the Book, along with a downloaded basic program Structyre
#"guess_my_number" ,found in the book companion's Website Files
#"www.courseptr.com/downloads" Chapter 3.
######EXPLANATION OF GUESS MY
NUMBER###################################################
#This program uses a random number generator(supplied by Python 3.4.0) to
#to pick a changeable number between 1 and 60. The User is prompted to guess
the number
#by inputting a guess at the prompt. The user is then advised whether the
correct number
#has been guessed. If it has been guessed correctly,the user is congratulated.
If the number
#has not been guessed correctly,the attempt is noted and quantified. then the
user is told whether
# the guess number was too large (and then for the user to guess a lower
number) or the number
#guessed was too small (and in this case for the user to guess a higher
number). The number of
#attempted non-successful guesses is accumulated and totalled and then when
finally the User guesses
#the correct number ; the guess attempts are outputted along with
Congatulations. The User is queried
#if they want to play the game again,if not,the Program ends.
##########################################################################################
####MAIN PROGRAM SECTION########################
#Use the random import module for a random number between 1 and 60
import random
print("\tWelcome to the Guess My Number Game! ")
print("\n The Mysterious Number to guess is between 1 and 60. ")
print("Try to guess the Mystery Number in as few tries as you can.\n")
#Enter Main Query Loop
print("Do you want to play the game?\n")
print("\n")
smv_grandCounter=int(input("Enter a 1 to play or 0 to exit: "))
while(smv_grandCounter=="1"):
#Enter the play game main loop area
smv_pickNumber=random.randint(1,60)
#Create by the computer by random number generator a mystery number
#Load random number into smv_pickNumber for storage
#Initialize the variable smv_attemptCounter to 1 for 1 initial pass through
the inner boundary values loop
smv_attemptCounter=1
#Get first pick for Number Identification Loop
#Initialize smv_guessNumber so Number Identification Loop can proceed with
Conditional
print("Think out a first guess between 1 and 60:")
smv_guessNumber= int(input("Take a guess!"))
#Enter Number Identification Loop
while(smv_guessNumber!=smv_pickNumber):
if (smv_guessNumber>smv_pickNumber):
print("Guess of mystery number Too high,enter a lesser number: \n")
smv_attemptCounter+=1
elif (smv_guessNumber < smv_pickNumber):
print("Guess of mystery number Too Low.Enter a greater number \n")
smv_attemptCounter+=1
elif (smv_guessNumber == smv_pickNumber):
#Print Congratulatory Message,the mystery number,the number of attempts
print("Congratulations! You have guessed the mystery number")
print("You have used",smv_attemptCounter,"sample picks.\n")
print("The mystery number was: ",pick_Number)
print("You have utilized",smv_attemptCounter,"attempts")
else:
print("You have entered a decimal number,a negative number or some other
Alphanumeric character")
print("Redo the loop with the correct values")
#Continue the loop,increment the number of attempts
smv_attemptCounter+=1
print("Enter a new integer guess:\n")
smv_guessNumber=int(input("Take a new guess!"))
#End the inner while Loop
print("Do you want to run the game again?")
#Stop the game,enter any integer number except 1
print("enter 1 to continue the game,other integer to end the game \n")
smv_grandCounter=int(input("Enter 1 to continue or 0 to stop the game: "))
#print out the variable names and their corresponding labels
print ("smv_grandCounter:Used in the Main Program While Loop as a Sentry
Variable for program entry and exit ")
print("smv_pickNumber:A main comparison variable,it receives a random number,
the \'mystery number\' an integer to guess ")
print("smv_guessNumber:An inputted variable,the User Guess,used to compare to
smv_pickNumber,to find the \'mystery\' number.")
print("smv_attemptCounter: This variable is used to give the Total number of
guesses needed by the User ")
input("\n\nPress the enter key to exit.")
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Welcome to the Guess My Number Game!
The Mysterious Number to guess is between 1 and 60.
Try to guess the Mystery Number in as few tries as you can.
Do you want to play the game?
Enter a 1 to play or 0 to exit: 1
Traceback (most recent call last):
File "E:\My Code\assignment4.py", line 51, in <module>
while(smv_guessNumber!=smv_pickNumber):
NameError: name 'smv_guessNumber' is not defined
>>>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor