Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python debugging hw
#1
### Debug this simple game program. The game should generate a random number between 0 and 100
### when the user hits Enter. The user can stop the game by typing "Stop".
### A score over 50 should result in a win.
import random
roll == raw_input("Press Enter to Spin the Wheel or Type ""Stop""!")
while roll == " ":
 prize = random.randint(0, 100)
 print "You're number is " str(prize) "!"
 if prize < 50
 print "Sorry, you didn't win. Try again"
 if prize > 50
 print "Congratulations! You're a winner!"
 roll = raw_input("Press Enter to Spin the Wheel or type 'stop'!")
if roll == "Stop":
 prnt "Thank you for playing"
else:
 print "Well, so long!"
This is the code I am trying to fix, and cant get it to run properly.
Here is what I have so far, can anyone help?

### Debug this simple game program. The game should generate a random number between 0 and 100
### when the user hits Enter. The user can stop the game by typing "Stop".
### A score over 50 should result in a win.
import random
roll = raw_input("Press Enter to Spin the Wheel or Type ""Stop""!")
while roll == " ":
    prize = random.randint(0, 100)
    print "Your number is " + str(prize) + '!'
    if prize < 50:
        print "Sorry, you didn't win. Try again"
        if prize > 50:
            print "Congratulations! You're a winner!"
roll = raw_input("Press Enter to Spin the Wheel or type 'stop'!")
if roll == "Stop":
    print "Thank you for playing"
else:
    print "Well, so long!"
Reply
#2
For starters, put your code in Python code tags. You can find help here.
It would also be helpful if you explained in more detail, what about your results is not right.
Reply
#3
I added the tags that j.crater mentioned, but do learn how to add them yourself. And j.crater is right that a more detailed question would be helpful.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
Just read over the link on code tags. Thank you for letting me know j.crater as I am still learning. Any ways the first script is the script that I was sent to work with. My problem - I can not get the while loop to run right. It skips the randomint method not giving me a result if i win or loose.

The game should generate a random number between 0 and 100 when the user hits Enter. The user should be able to stop the game by typing "Stop". A score over 50 should result in a win. Analyze existing Python code to identify and correct all bugs and correct all errors within the debugging file (attached) to this module.
Reply
#5
Why would it skip that? On what line would it skip the randint call?

Normally I would just tell you what is wrong with the code. But since the homework is for you to figure out what is wrong with the code, I'm just going to ask questions pointing you in the right direction.

And tell your teacher that we said they should be teaching Python 3.7.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
Our department is small, and the class is not well developed. Basically a test trial to see how it goes. I'm not sure that it is skipping it. My code will not print back the randint, print if I won or lost. I believe I am missing something or the randint isn't in the right place.
Reply
#7
Trust me. It's skipping the randint.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
import random

roll = raw_input("Press Enter to Spin the Wheel or Type ""stop""!") 

while roll == "":
    prize = random.randint(0, 100)
    print "You're number is " + str(prize) + "!"
    if prize < 50:
        print "Sorry, you didn't win. Try again"
    if prize > 50:
        print "Congratulations! You're a winner!"
    break


roll = raw_input("Press Enter to Spin the Wheel or type 'Stop'!")

if roll == "Stop":
    print "Thank you for playing"
else:
    print "Well, so long!"
Reply
#9
Did you solve that problem? I know whether you did or not, but I want to know if you're checking your solutions.

If you did, what's the next problem you're having?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#10
Ok, I didn't see the space on line 3, so I removed that and added a break. Problem finally solved. Thanks all

Let's say if the user lost the game, meaning has gotten a number less than 50. And the user wanted to continue to play, how would I adjust the script to allow multiple spins?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Program debugging (python) abdullahali 5 3,309 Jan-17-2019, 04:31 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020