python - Python3x Integer and String Input -


i want user input number give number : types "10" -but... give number : types "i want type 10" want program "count" integer. because if types string program stop

import random goal = random.randrange(1,10) n = 1  tries = 0  name = input("dose onoma sou ")  print("a game in python") while n != 0 :      value = int(input("madepse poio einai noumero:"))      n = abs(value - goal)     print(value,n)     tries = tries + 1     if n >= 4 :      print("den eisai koda")     elif n > 0 , 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 

this take input , pull first number out of it. \d matches digit 0-9, , + means "one or more".

import re  while true:     user = input('enter number: ')     match = re.search(r'\d+',user)     if match:         value = int(match.group(0))         break     else:         print("i didn't see number in response.")  print(value) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -