Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-检查字符的多个字符串值_Python_While Loop - Fatal编程技术网

Python-检查字符的多个字符串值

Python-检查字符的多个字符串值,python,while-loop,Python,While Loop,我知道这是我今天问的其他问题的双重组合。但这是最新的,我已经把其他的都删除了 这是我目前的代码: def Main(): 字符=集合('0123456789') 尽管如此: Class_A_Input = raw_input('Enter Class A tickets sold: ') Class_B_Input = raw_input('Enter Class B tickets sold: ') Class_C_Input = raw_input('Enter Cla

我知道这是我今天问的其他问题的双重组合。但这是最新的,我已经把其他的都删除了

这是我目前的代码:

def Main():

字符=集合('0123456789')

尽管如此:

   Class_A_Input = raw_input('Enter Class A tickets sold: ')

   Class_B_Input = raw_input('Enter Class B tickets sold: ')

   Class_C_Input = raw_input('Enter Class C tickets sold: ')

   if any((c in chars) for c in Class_A_Input):

       break

   else:

       print 'Wrong'
当一次只有一个用户输入时,我能够使用“如果有((字符中的c)表示类中的c_A_输入)”

有没有办法用这种方法检查所有3个用户输入,如果没有问题就中断循环,否则显示“错误”,并重新启动循环供用户输入

谢谢你的耐心和帮助。

这会有用的

try:
   int(Class_A_Input)
   int(Class_B_Input)
   int(Class_C_Input)
   break
except ValueError:
   print "Wrong"
这会奏效的

try:
   int(Class_A_Input)
   int(Class_B_Input)
   int(Class_C_Input)
   break
except ValueError:
   print "Wrong"

我想你要检查用户的输入是否有数字,如果是的话, 然后你可以用

import re

def hasDigit(s):
    return not not re.search("\d", s)

def Main():
    while True:
        Class_A_Input = raw_input('Enter Class A tickets sold: ')
        Class_B_Input = raw_input('Enter Class B tickets sold: ')
        Class_C_Input = raw_input('Enter Class C tickets sold: ')

        if all([hasDigit(Input) for Input in [Class_A_Input, Class_B_Input, Class_C_Input]]):
            break
        else:
            print 'Wrong'

我想你要检查用户的输入是否有数字,如果是的话, 然后你可以用

import re

def hasDigit(s):
    return not not re.search("\d", s)

def Main():
    while True:
        Class_A_Input = raw_input('Enter Class A tickets sold: ')
        Class_B_Input = raw_input('Enter Class B tickets sold: ')
        Class_C_Input = raw_input('Enter Class C tickets sold: ')

        if all([hasDigit(Input) for Input in [Class_A_Input, Class_B_Input, Class_C_Input]]):
            break
        else:
            print 'Wrong'

最后两个问题出了什么问题?你为什么不编辑它们?最后两个问题怎么了?为什么不编辑它们呢?另外:
somestring.isdigit()
是真的,如果
somestring
完全由数字组成。另外:
somestring.isdigit()
是真的,如果
somestring
完全由数字组成。