![]() |
|
[Python] Trying to make a &[b]#34[/b];guess the number&[b]#34[/b]; game, why doesn't this work? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Trying to make a &[b]#34[/b];guess the number&[b]#34[/b]; game, why doesn't this work? (/showthread.php?tid=3801630) |
Trying to make a &[b]#34[/b];guess the number&[b]#34[/b]; game, why doesn't this work? - ๖ۣۜQ - Oct 12, 2013 Just started learning Python and I tried making a "guess the number" game where you set the minimum and maximum numbers yourself, but it gives me errors. Could anyone tell me how to fix this? Thanks in advance! Code import randomThese are the errors I'm getting: Code Traceback (most recent call last):* - Skyla Blue - Oct 12, 2013 You need to put min_num and max_num in the global scope, i.e not inside a function. * - monkeytherat - Oct 12, 2013 (Oct 12, 2013 12:45 PM)Skyla Blue Wrote: You need to put min_num and max_num in the global scope, i.e not inside a function. It's better form to pass them as parameters and define them in the game function. * - glob - Oct 12, 2013 (Oct 12, 2013 12:59 PM)monkeytherat Wrote: It's better form to pass them as parameters and define them in the game function. There are hundreds of ways to improve the code, he just told OP what needed to be done to get the error to go away. * - BeerMonger - Oct 14, 2013 (Oct 12, 2013 12:44 PM)๖ۣۜQ Wrote:question, what does that "chance()" refer to? Is it defined somewhere? am I missing something? * - Skyla Blue - Oct 14, 2013 (Oct 14, 2013 01:22 AM)BeerMonger Wrote: question, what does that "chance()" refer to? LOL good catch, I didn't see that. That would also cause a problem, after his other one. * - BeerMonger - Oct 14, 2013 Thought I was being an idiot and missing something obvious XD Woohoo I'm not an idiot 😝 Another thing is that in this line: Code pc = int(input("Enter a number between " + min_num + " and " + max_num + "."))Code pc = int(input("Enter a number between " + str(min_num) + " and " + str(max_num) + "."))* - Skyla Blue - Oct 14, 2013 (Oct 14, 2013 01:47 AM)BeerMonger Wrote: ... Why would you do that? Then you can't compare the two numbers, because they will be strings. * - BeerMonger - Oct 14, 2013 Can you add ints to a string just like that? using "+"? Cause when I tried it that didn't work. * - Skyla Blue - Oct 14, 2013 (Oct 14, 2013 02:05 AM)BeerMonger Wrote: Can you add ints to a string just like that? using "+"? No that doesn't work, you'd have to convert to one data type, or another. * - BeerMonger - Oct 14, 2013 So I was right..You do need to convert them to strings then back to ints.. Or how would you do it in another way that wont convert them to strings Skyla? * - Skyla Blue - Oct 14, 2013 (Oct 14, 2013 02:19 AM)BeerMonger Wrote: So I was right..You do need to convert them to strings then back to ints.. What part are you talking about? I'm confused. * - BeerMonger - Oct 14, 2013 (Oct 14, 2013 01:47 AM)BeerMonger Wrote: Another thing is that in this line: (Oct 14, 2013 02:01 AM)Skyla Blue Wrote: Why would you do that? Then you can't compare the two numbers, because they will be strings. You asked why would I do that and said I won't be able to compare the numbers.. But in order to do what the poster wanted to do you have to convert them to strings.. So I was right in that ^^ (only later on you will need to convert them back to int) * - Skyla Blue - Oct 14, 2013 Oh you're right in that part, I thought you were talking about the actual comparing. * - BeerMonger - Oct 14, 2013 KK, just a misunderstanding [: Anyways Poster read the comments and see whats wrong in your code! |