Number Guess: Python file not responding. please help


#1

Hi. I have got the correct code and I can’t see anything wrong with it but when I type the file in for the freeform project, nothing happens.
Any ideas?
Happy to provide photos of code and errors.
Thanks.

Here’s the code:

"""This is a number guessing game the idea is that the player/you will guess a number, and the program will decide who the winner is, if the player/you guess is BIGGER than the dice rolled result, then the player/you wins. Otherwise the computer wins"""
from random import randint
from time import sleep
def get_user_guess():
  user_guess = int(raw_input ("Please input your guess, it's two dice!: "))
  return user_guess
def roll_die(number_of_sides):
  roll_dice(6)
  first_roll = randint(1, number_of_sides)
  second_roll = randint(1, number_of_sides)
  max_val = number_of_sides * 2
  print "The max value that can be a roll: " + str(max_val)
  sleep (1)
  user_guess = get_user_guess()
  if user_guess > max_val:
    print "Your guess is too big, it's six sides after all!"
    return 
  else: 
    print "Rolling..."
    sleep (2)
    print "The first roll is resulting too: %d" % first_roll
    sleep (1)
    print "The second roll is resulting too: %d" % second_roll
    total_roll = first_roll + second_roll
    print "The total roll is resulting too: %d" % total_roll
    if user_guess > total_roll:
      print "You win!"
      return
    else:
      print "You lost!"
      return

#2

Please be sure to include a link to the project when posting a question. Thanks.

Link to NumberGuess.py project

Python extension course

Your code was formatted to display block structure.


#3

Should this line follow your code and be called from global scope? It is an infinite loop that should crash very quickly.


#5

https://www.codecademy.com/courses/learn-python/projects/number-guess

is this what you mean by linking it?


#6

Yes, that is. Thanks.


#7

A file doesn’t do anything by itself, try running python with the filename as an argument

Or if that’s what you did, then consider what your program does when executed. Maybe the instructions in your file amount to doing nothing.
You can test with a simpler program which you know does something, to determine if you’re running it correctly

print 'hello world'

#8

I tried printing “Yay” and it still doesn’t work, nothing responds. What do you mean by running it as an argument?
Thanks


#9

Python is a program. The way you execute python programs is by running python, and telling it which file to execute - python path/to/file.py

Your code says to make two imports and create two functions. After that it’s done, that’s all it does.

By running a program that ONLY contains a print, you could determine if the problem is with the code itself or not. I suspect you put the print somewhere in your already existing code though, but already knowing that prints don’t come out of there, that defeats the purpose.


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.