Python Forum

Full Version: Converting pseudocode to Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi there,

First python project, need to convert the psuedocode which I wrote below to python. Don't actually need the program to work just need the python code. Brand new to this stuff, would appreciate someone helping me out.
qwerty

number = RAN_NUMBER
count_attempts = 0
answer_status = (“incorrect”)
while answer_status = (“incorrect”)
guess = input (“please guess number)
count_attempts = count_attempts +1
if guess = number then print (“well done. count_attempts”)
answer_status=(“correct”)
else print (“number of digits correct”)
endif
endwhile
You have to make some effort on your own to convert it.
What have you tried? We are glad to help, but we are not here to do your homework for you.
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
You are lucky as python code is so close to natural language, that your pseudo-code needs very little in order to turn into real python code.
Also, it's funny to say you don't need the program to work, just the python code :-)
Okay here is my code

import random
number = random.randint(1000,9999)
print number
count_attempts = 0
answer_status = "incorrect"
while(answer_status == "incorrect"):
guess = input ("please guess number")
count_attempts = count_attempts + 1
if guess == number:
print ("well done. The number of attempts it took were")
print count_attempts
answer_status = "correct"
else:
print("number of digits correct")

I need to insert a function which allow me to say when I get the answer wrong it will print the number of digits from the number that i guessed were right. Any ideas?