How can I print a string when the user presses the enter key whilst playing my guessing game?

Josh S

I am a beginner programmer and I've created a guessing game but I want to incorporate a string that will print when the user presses the enter key and I've tried this but it does not work. (Returns the error, "ValueError: invalid literal for int() with base 10") when the user presses enter.

The program works fine if the user does not press enter and only inputs integers.

highest = 12
lowest = 6
answer = 9


input("Press enter to play a guessing game")




guess = input("Guess a number from %d " %lowest + "to %d: " %highest)






while (int(guess) != answer) or guess == ():
    if int(guess) > answer:
        print ("Answer is lower")
    elif guess == ():
        print ("That's not valid") 




    else:
        print("Answer is higher")



guess = input("Guess again ")

print ("Correct!!") 
wiki
import random
a = int
b = int
c= int
def guessing():

      guess = int(input("guess an no between 1 to 10: "))
      c = random.randrange(1,11)
      print("answer is",c)
      if (guess == c):
            print("correct guess")
      elif(guess>c):
            print("higher")
      else:
            print("lower")

d=input("\n\n Y TO START \n n to exit\n")
if (d == "y" or d == "Y"):
      guessing()
elif(d =="n" or d == "N"):
      print("exit")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I wire up a button on my page so that it is clicked when a user presses enter?

From Dev

How to trigger a Tab when user presses Enter

From Dev

How can I play a sound when a user presses a button in a MessageBox?

From Dev

angular ui-grid filter when user presses enter key

From Dev

How can I prevent my iOS VoIP app from playing audio when the user switches their phone to silent?

From Dev

How to run a function when user presses enter on input field?

From Dev

how to get output when user just presses enter in c++

From Dev

how to get output when user just presses enter in c++

From Dev

How do I close my prompt when the user presses the ESC button?

From Dev

How do I close my prompt when the user presses the ESC button?

From Dev

How can I delete a Firebase document when user presses the Power button

From Dev

How can I print output whilst detached from controlling terminal?

From Dev

How can I bind the Enter key to my tkinter window

From Dev

Fire observable subscribe function first when user presses enter key using custombinding

From Dev

How can I catch 2+ key presses at once?

From Dev

How can I emulate key presses on Vim startup?

From Dev

How can I store key presses into variables to refactor this code?

From Dev

How can I map repeated key presses to specific?

From Dev

How can I iterate each time the user presses a button?

From Dev

How do I "Pause" a console application when the user presses escape?

From Dev

How can I fire the Tab keypress when the Enter key is pressed?

From Dev

How to stop Enter Key presses triggering the Submit button on my HTML form

From Dev

How can I append user input to a new line whilst also avoiding possible duplicates within my .CSV file using FileWriter?

From Dev

how I can disabled default submit in asp:ImageButton when user hit enter key asp.net c#

From Dev

how can i get my function to go through the dictionary and check if the key exists when user inputs

From Dev

How can I implement a button in my app so every time a user presses it, the whole app default colour changes

From Dev

Jquery Mobile Listview Autocomplete: how to trigger function when user presses enter?

From Dev

How do I guarantee that a Java Swing JDialog will maintain focus and register all key presses in game?

From Dev

How do I subtract coins in my game when the user buys in game items in Swift?

Related Related

  1. 1

    How can I wire up a button on my page so that it is clicked when a user presses enter?

  2. 2

    How to trigger a Tab when user presses Enter

  3. 3

    How can I play a sound when a user presses a button in a MessageBox?

  4. 4

    angular ui-grid filter when user presses enter key

  5. 5

    How can I prevent my iOS VoIP app from playing audio when the user switches their phone to silent?

  6. 6

    How to run a function when user presses enter on input field?

  7. 7

    how to get output when user just presses enter in c++

  8. 8

    how to get output when user just presses enter in c++

  9. 9

    How do I close my prompt when the user presses the ESC button?

  10. 10

    How do I close my prompt when the user presses the ESC button?

  11. 11

    How can I delete a Firebase document when user presses the Power button

  12. 12

    How can I print output whilst detached from controlling terminal?

  13. 13

    How can I bind the Enter key to my tkinter window

  14. 14

    Fire observable subscribe function first when user presses enter key using custombinding

  15. 15

    How can I catch 2+ key presses at once?

  16. 16

    How can I emulate key presses on Vim startup?

  17. 17

    How can I store key presses into variables to refactor this code?

  18. 18

    How can I map repeated key presses to specific?

  19. 19

    How can I iterate each time the user presses a button?

  20. 20

    How do I "Pause" a console application when the user presses escape?

  21. 21

    How can I fire the Tab keypress when the Enter key is pressed?

  22. 22

    How to stop Enter Key presses triggering the Submit button on my HTML form

  23. 23

    How can I append user input to a new line whilst also avoiding possible duplicates within my .CSV file using FileWriter?

  24. 24

    how I can disabled default submit in asp:ImageButton when user hit enter key asp.net c#

  25. 25

    how can i get my function to go through the dictionary and check if the key exists when user inputs

  26. 26

    How can I implement a button in my app so every time a user presses it, the whole app default colour changes

  27. 27

    Jquery Mobile Listview Autocomplete: how to trigger function when user presses enter?

  28. 28

    How do I guarantee that a Java Swing JDialog will maintain focus and register all key presses in game?

  29. 29

    How do I subtract coins in my game when the user buys in game items in Swift?

HotTag

Archive