Python3x Integer and String Input

Portgas D Ace

I want the user to input a number Give a number : he types "10" -but... Give a number : he types "I want to type 10" i want the program to just "count" the integer. Because if he types a string the program will stop

import random
goal = random.randrange(1,10)
n = 1 
tries = 0 
name = input("Dose to onoma sou ")

print("A game in Python")
while n != 0 : 
    value = int(input("madepse poio einai to noumero:")) 
    n = abs(value - goal)
    print(value,n)
    tries = tries + 1
    if n >= 4 :
     print("den eisai koda")
    elif n > 0 and n <= 3 :
     print("eisai koda")
    else :
     print("to vrikes")
     print ("to score sou einai: ",tries)

skoros = str(tries)
score = open('score.txt', 'a')
score.write(name)
score.write(' ') 
score.write(skoros)
score.write("\n") 
score.close
Mark Tolonen

This will take any input and pull the first number out of it. \d matches any digit 0-9, and + means "one or more".

import re

while True:
    user = input('Enter a number: ')
    match = re.search(r'\d+',user)
    if match:
        value = int(match.group(0))
        break
    else:
        print("I didn't see a number in that response.")

print(value)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python string input to integer conversion

From Dev

Python 3 int() function is not converting input string to integer

From Dev

InputMismatchException for String input into integer field

From Dev

File input containing string and integer

From Dev

InputMismatchException for String input into integer field

From Dev

String to Integer Input Verification Conversion

From Dev

invalid input syntax for integer (string)

From Dev

Python: Analyzing input to see if its an integer, float, or string

From Dev

how to check whether raw_input is integer, string and date in python

From Dev

string is not same in Python3x as for Python2.x but Still it is working

From Dev

Python long integer input

From Dev

integer input validation python

From Dev

Python long integer input

From Dev

Turning an integer string to an integer in Python

From Dev

How to input integer values in a list(python 3.x)?

From Dev

Reading String and Integer input from text file

From Dev

NumberFormatException given an input String holding a small integer

From Dev

Java Scanner not accepting integer input before string

From Dev

Returning a string given a particular integer input

From Dev

Using Scanf() for taking input for both string and integer

From Dev

NumberFormatException given an input String holding a small integer

From Dev

Input String where Integer should be - C++

From Dev

How convert input String to Integer groovy

From Dev

Java Scanner not accepting integer input before string

From Dev

Reading String and Integer input from text file

From Dev

checking if an input of an integer is a string with try catch

From Dev

error in taking input string after integer in java

From Dev

Taking input in integer /string and store it in array

From Dev

number format Exception for input string to integer

Related Related

  1. 1

    python string input to integer conversion

  2. 2

    Python 3 int() function is not converting input string to integer

  3. 3

    InputMismatchException for String input into integer field

  4. 4

    File input containing string and integer

  5. 5

    InputMismatchException for String input into integer field

  6. 6

    String to Integer Input Verification Conversion

  7. 7

    invalid input syntax for integer (string)

  8. 8

    Python: Analyzing input to see if its an integer, float, or string

  9. 9

    how to check whether raw_input is integer, string and date in python

  10. 10

    string is not same in Python3x as for Python2.x but Still it is working

  11. 11

    Python long integer input

  12. 12

    integer input validation python

  13. 13

    Python long integer input

  14. 14

    Turning an integer string to an integer in Python

  15. 15

    How to input integer values in a list(python 3.x)?

  16. 16

    Reading String and Integer input from text file

  17. 17

    NumberFormatException given an input String holding a small integer

  18. 18

    Java Scanner not accepting integer input before string

  19. 19

    Returning a string given a particular integer input

  20. 20

    Using Scanf() for taking input for both string and integer

  21. 21

    NumberFormatException given an input String holding a small integer

  22. 22

    Input String where Integer should be - C++

  23. 23

    How convert input String to Integer groovy

  24. 24

    Java Scanner not accepting integer input before string

  25. 25

    Reading String and Integer input from text file

  26. 26

    checking if an input of an integer is a string with try catch

  27. 27

    error in taking input string after integer in java

  28. 28

    Taking input in integer /string and store it in array

  29. 29

    number format Exception for input string to integer

HotTag

Archive