Posts: 5
Threads: 1
Joined: Oct 2018
Oct-05-2018, 04:53 PM
(This post was last modified: Oct-05-2018, 06:29 PM by ichabod801.)
### 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!"
Posts: 1,150
Threads: 42
Joined: Sep 2016
Oct-05-2018, 06:08 PM
(This post was last modified: Oct-05-2018, 06:08 PM by j.crater.)
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.
Posts: 4,220
Threads: 97
Joined: Sep 2016
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.
Posts: 5
Threads: 1
Joined: Oct 2018
Oct-05-2018, 06:58 PM
(This post was last modified: Oct-05-2018, 06:58 PM by John0895.)
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.
Posts: 4,220
Threads: 97
Joined: Sep 2016
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.
Posts: 5
Threads: 1
Joined: Oct 2018
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.
Posts: 4,220
Threads: 97
Joined: Sep 2016
Trust me. It's skipping the randint.
Posts: 5
Threads: 1
Joined: Oct 2018
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!"
Posts: 4,220
Threads: 97
Joined: Sep 2016
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?
Posts: 5
Threads: 1
Joined: Oct 2018
Oct-05-2018, 09:30 PM
(This post was last modified: Oct-05-2018, 09:55 PM by John0895.)
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?
|