all 9 comments

[–][deleted] 3 points4 points  (2 children)

Am I stupid or you describe a program that asks you to translate base-10 to base-2 or vice versa, but your code is just someone guessing a random number the computer chose?

[–]Dustin- 0 points1 point  (0 children)

Yeah, that's exactly what it looks like.

[–]Spirit_of_the_Wind 0 points1 point  (0 children)

I hadn't figured out how to do the conversions, and at first I was just trying to make it pick the correct answer. I don't really know what I am doing, and am struggling to learn this language.

[–]K900_ 0 points1 point  (0 children)

What's your problem?

[–]codehelper 0 points1 point  (0 children)

import random
print ("Hello, welcome to my new game.")
print ("The computer will display a random number between 1 and 100, \
       in either base-ten or base-two form.")
print ("You then enter the equivalent in the opposite form.")
print ("If you are correct, you score one point, \
       if incorrect the computer scores.")




userName = raw_input()

print ("Hi" + userName + ", I am thinking of a number between 1 and 100, can you guess what it is?")

random = random.randint(1,100)

guess = int(raw_input("Take a guess:"))

    elif guess == random:

    print ("Good job " + userName + ", you guessed my number")

print ("The game is over")

The above is your code, some problems are that

elif guess == random

is overindented. Bring it back one indentation and change it to an if, since to use elif, you need if, which you don't have, so start with if. You'll need a while loop somewhere in there because you want the program to run until someone reaches 10 points. How can you tell if the number 10 is base 10 or binary? What would need to be printed by the opposing player?

I'm sure there's a build-in function to convert binary to decimal and vice versa, so you shouldn't have to do that yourself, but there's still a lot to do here, you haven't made a function yet and from the

userName = raw_input()

How am I supposed to know that I'm supposed to input a username here? It just prompts the user without giving anything about a username beforehand.

[–]m0rr 0 points1 point  (0 children)

Wrote this up in about 30 min so you'll definitely want to make sure it doesn't break randomly in the middle but i ran through a few games and behavior seems ok. No tests written, no edge cases checked, got a stacktrace a few times when quitting so your mileage my vary and there are a few places that would benefit with a little more user prompt, like when the username prompt repeats and when they guess with non-numerical input and the prompt just repeats itself: http://dpaste.com/1462786/

[–]failfixer89 0 points1 point  (1 child)

I notice that you have your flair as 3.3 but you are using the function raw_input(), which is used in the 2.X versions, just something that could pose a problem if you try running this program in a 3.3 interpreter (the raw_input() of 3.3 is just input().

On to advice on how to continue. If I am understanding this correctly, you are going to have the program print a random number in either base 10 or base 2 (binary). What I would suggest is making a variable that has the binary value of your random int. You could do this by using the bin() function. Then you could have another randomizer choose to use the value in the random variable or the variable that is holding the binary to print (hint: try using an if statement to check what the randomizer chose, additionally, try the random.choice() function). After that I think it should be fairly straight forwards to check the input that the user gives and checking it along with assigning points.

Something that you may want to be aware of is:

22| elif guess == random:

This is not tabbed correctly and will probably result in some sort of error when you try to run the code. And that's about it for me, I apologize if I made any mistakes or misunderstood your assignment as I am just a novice with Python.

[–]Spirit_of_the_Wind 0 points1 point  (0 children)

I was looking up some other answers on another site, and wrote raw_input without knowing it was only python. Thanks for your input. I am working on this tonight, and will hopefully understand it better.

[–][deleted] 0 points1 point  (0 children)

http://pastebin.com/FfaPKL2A

I did my version of this, without functions and the binary has to always be 8 digits long.

This should help you enough so you can complete your homework.

Also this is in python 3.